嵌套select多个表
嵌套select多个表
我有4个表
t1
t1ID column1 t2ID t4ID
1 a 5 4
2 b 1 2
3 c 3 2
4 d 5 1
5 e 4 3
t2
ID column2 t3ID
1 a 5
2 c 2
3 d 4
4 e 1
5 d 2
t3
ID column3
1 z
2 y
3 w
4 u
5 p
t4
ID column4
1 y
2 t
3 q
4 q
4个表的关系
t1.t2id=t2.id
t2.t3id=t3.id
t1.t4id=t4.id
当t1.t1ID=3时,要怎样select法才能获得如下结果呢?
t1ID column1 column2 column3 column4
3 c d u t
(目前我的水平只会写两级的select
select t1.ID, t1.column1, t2.column2 from
t1 inner join t2 on t1.t2id=t2.id)谢谢
另,能推荐一本专门论述这类错综复杂的select方面具实践性的书么,联机帮助真的很枯燥阿
------解决方案--------------------select T1.t1ID, T1.column1, T2.column2, T3.column3, T4.column4
from T1
inner join T2 on T1.t2ID=T2.ID
inner join T4 on T1.t4ID=T4.ID
inner join T3 on T2.t3ID=T3.ID
where T1.t1ID=3
------解决方案--------------------left
inner
自己去玩