表1 
A   B
a   0
b   0
c   0
d   0
e   0
表2
A   B
c   1
e   1合并两个表除去重复的数据(以表2的数据为主),得到以下表
A   B
a   0
b   0
d   0
c   1
e   1

解决方案 »

  1.   

    SELECT a,MAX(B) b FROM 
    (SELECT A,B FROM tb1
    UNION
    SELECt A,B FROM tb2) x
    GROUP BY a
      

  2.   

    select distinct * from (SELECT * from A union select * from b) a
    没测试!
      

  3.   

    declare @temp table (a1 char ,a1r int)
    insert into @temp
    select 'a',   0 union all
    select 'b' ,  0 union all
    select 'c' ,  0 union all
    select 'd' ,  0 union all
    select 'e'  , 0
     declare @tempb table (a1 char ,a1r int)
    insert into @tempb
    select 'c',  1 union allselect 'e'  , 1
    insert into   @tempb (a1,a1r) select a1,a1r from @temp a where not exists(select 1 from @tempb b where a.a1=b.a1)
    select * from @tempb
      

  4.   

    select isnull(a.a,b.a),isnull(a.b,b.b)
    from tb2 a
    full join tb1 b
    on a.a =b.a