SELECT a,MAX(B) b FROM (SELECT A,B FROM tb1 UNION SELECt A,B FROM tb2) x GROUP BY a
select distinct * from (SELECT * from A union select * from b) a 没测试!
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
select isnull(a.a,b.a),isnull(a.b,b.b) from tb2 a full join tb1 b on a.a =b.a
(SELECT A,B FROM tb1
UNION
SELECt A,B FROM tb2) x
GROUP BY a
没测试!
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
from tb2 a
full join tb1 b
on a.a =b.a