日期:2014-05-17 浏览次数:20528 次
create table table1
(id int,nameA varchar(50))
create table table2
(id int,nameB varchar(50),aid int)
create table table3
(id int,nameC varchar(50),bid int)
insert into table1
select 1,'a'
insert into table2
select 1,'b',1 union all
select 2,'b2',1
insert into table3
select 1,'c',1
select a.nameA,b.nameB,c.nameC
from table1 a
left join table2 b on a.nameA=b.nameB
left join table3 c on a.nameA=c.nameC
union all
select a.nameA,b.nameB,c.nameC
from table1 a
left join table2 b on a.id=b.aid
left join table3 c on a.nameA=c.nameC
union all
select a.nameA,c.nameB,c.nameC
from table1 a
left join
(
select a.nameB,b.nameC,a.id
from table2 a
left join table3 b on a.id=b.bid
)c on a.id=c.id