两个表中都有UserName字段,现在需要两个表中所有的UserName,如何做?
- SQL code
select distinct UserName from table1union allselect distinct UserName from table2
这个不能剔除两个合并以后重复的,要怎么解决?
------解决方案--------------------
select distinct UserName from table1
union
select distinct UserName from table2
------解决方案--------------------
select UserName from table1
union
select UserName from table2
--返回两个表的所有的UserName ,且去掉重复的
------解决方案--------------------
- SQL code
select UserName from table1union select UserName from table2
------解决方案--------------------
把 all 去掉
------解决方案--------------------
- SQL code
select UserName from tbl1union select UserName from tbl2--union all 是不去重的