8

我可以将左外连接放在另一个左外连接内吗?像这样:

SELECT * FROM table1 
LEFT OUTER JOIN table2 ON (LEFT OUTER JOIN table 3 ON (Join Conditions))
WHERE
....(where conditions)
4

1 回答 1

14

To group multiple joins, the syntax is as follows (untested on db2)

SELECT *
FROM table1 t1
LEFT JOIN (
  table2 t2 INNER JOIN table3 t3 ON t3.someId = t2.someId
) ON t2.someId = t1.someId

Same syntax for left join inside LEFT JOIN(), but please read comment by @X-Zero

SELECT *
FROM table1 t1
LEFT JOIN (
  table2 t2 LEFT JOIN table3 t3 ON t3.someId = t2.someId
) ON t2.someId = t1.someId
于 2012-05-01T11:41:33.743 回答