22,209
社区成员
发帖
与我相关
我的任务
分享
create table #1(A int,B int,C int)
insert #1 values(1,1,2)
insert #1 values(1,2,3)
insert #1 values(1,3,5)
create table #2(A int,B int,D int)
insert #2 values(1,1,3)
insert #2 values(1,3,4)
insert #2 values(1,4,6)
select isnull(#1.a,#2.a) A,isnull(#1.b,#2.b) B,#1.C,#2.d from #1 full join #2 on #1.a = #2.a and #1.b = #2.b
A B C d
----------- ----------- ----------- -----------
1 1 2 3
1 2 3 NULL
1 3 5 4
1 4 NULL 6
(4 row(s) affected)
create table Table1( a int,b int,c int)
insert into table1 values(1 , 1 , 2)
insert into table1 values(1 , 2 , 3)
insert into table1 values(1 , 3 , 5)
create table table2(a int,b int , d int)
insert into table2 values(1 , 1 , 3 )
insert into table2 values(1 , 3 , 4 )
insert into table2 values(1 , 4 , 6 )
go
select isnull(m.a , n.a) a,
isnull(m.b , n.b) b,
m.c,
n.d
from table1 m full join table2 n
on m.a = n.a and m.b = n.b
order by m.a , m.b
drop table table1 , table2
/*
a b c d
----------- ----------- ----------- -----------
1 1 2 3
1 2 3 NULL
1 3 5 4
1 4 NULL 6
(所影响的行数为 4 行)
*/
select isnull(m.a , n.a),
isnull(m.b , n.b),
m.c,
n.d
from table1 m full join table2
on m.a = n.a and m.b = n.b