34,838
社区成员




create table A(ID int,name varchar(10),Address varchar(10))
insert into A values(1, 'Jerry', 'GuanZhuo' )
create table B(ID int,name varchar(10),Address varchar(10))
insert into B values(1, 'Joy', 'ShanHai ' )
create table c(OrderID int,Name varchar(10))
insert into c values(1, 'Jerry')
insert into c values(2, 'Joy')
go
select c.* , t.id , t.address
from c left join (select * from a union all select * from b) t
on c.name = t.name
drop table a,b,c
/*
OrderID Name id address
----------- ---------- ----------- ----------
1 Jerry 1 GuanZhuo
2 Joy 1 ShanHai
(2 行受影响)
*/
select a.*,b.id,b.address
from 表C a,
(select id,name,address from 表A union all select id,name,address from 表B) b
where a.name=b.name
select c.*,
isnull(a.id,b.id) as id,
isnull(a.Address,b.Address ) as Address
from c left join a on c.name=a.name
left join b on c.name=b.name
select c.* , t.id , t.address
from c left join (select * from a union all select * from b) t
on c.name = t.name