请教多表查询的问题
我有4个表 分别为 tab1,tab2,tab3,tab4
tab1如下:
id name tab2_id tab3_id tab4_id
tab2如下:
id name remark
tab3如下:
id name
tab4如下:
id name
我想得到这样一个表
tab_temp
id name tab2_name tab2_remark tab3_name tab4_name
请问
如何写SQL把这几个表连接起来,得到一个 tab_temp 的表
高手们请指教
[解决办法]
SELECT T1.ID AS ID,T1.NAME AS NAME,T2.NAME AS tab2_name,T2.REMARK AS tab2_remark,T3.NAME AS tab3_name,T4NAME AS tab4_name
FROM Tab1 T1 LEFT JOIN
Tab2 T2 ON T1.ID=T2.ID LEFT JOIN
Tab3 T3 ON T1.ID=T3.ID LEFT JOIN
Tab4 T4 ON T1.ID=T4.ID
[解决办法]
select tab1.id , tab1.name , b.name tab2_name , b.remark tab2_remark , c.name tab3_name , d.name tab4_name from tab1
left join tab2 on tab1.id = b.id
left join tab3 on tab1.id = c.id
left join tab4 on tab1.id = d.id