我可以将左外连接放在另一个左外连接中吗?像这样:
SELECT * FROM table1
LEFT OUTER JOIN table2 ON (LEFT OUTER JOIN table 3 ON (Join Conditions))
WHERE
....(where conditions)
答案 0 :(得分:11)
要对多个联接进行分组,语法如下(在db2上未经测试)
SELECT *
FROM table1 t1
LEFT JOIN (
table2 t2 INNER JOIN table3 t3 ON t3.someId = t2.someId
) ON t2.someId = t1.someId
LEFT JOIN()
内左连接的语法相同,但请阅读@ X-Zero的评论
SELECT *
FROM table1 t1
LEFT JOIN (
table2 t2 LEFT JOIN table3 t3 ON t3.someId = t2.someId
) ON t2.someId = t1.someId