两个表中都有UserName字段,现在需要两个表中所有的UserName,如何做?select distinct UserName from table1
union all
select distinct UserName from table2
这个不能剔除两个合并以后重复的,要怎么解决?

解决方案 »

  1.   

    select distinct UserName from table1
    union
    select distinct UserName from table2
      

  2.   

    select  UserName from table1
    union 
    select  UserName from table2
    --返回两个表的所有的UserName ,且去掉重复的
      

  3.   

    select UserName from table1
    union  
    select UserName from table2
      

  4.   

    select distinct  UserName from table1
    union all
    select distinct  UserName from table2
    --返回量表的所有的UserName ,即使两表重复的也不去掉distinct  只用去去掉当前查询的表的重复行
      

  5.   


    select UserName from tbl1
    union  
    select UserName from tbl2
    --union all 是不去重的
      

  6.   


    select distinct UserName from table1
    union 
    select distinct UserName from table2