【发布时间】:2010-07-15 14:07:03
【问题描述】:
SELECT
a.foo
b.bar
c.foobar
FROM tableOne AS a
INNER JOIN tableTwo AS b ON a.pk = b.fk
LEFT JOIN tableThree AS c ON b.pk = c.fk
WHERE a.foo = 'something'
AND c.foobar = 'somethingelse'
在 where 子句之后加上 and 子句似乎将左连接变成了内连接。我看到的行为是,如果 tableThree 中没有“somethingelse”,则将返回 0 行。
如果我将 c.foobar = 'somethingelse' 移动到连接子句中,存储的连接将像左连接一样。
SELECT
a.foo
b.bar
c.foobar
FROM tableOne AS a
INNER JOIN tableTwo AS b ON a.pk = b.fk
LEFT JOIN tableThree AS c ON b.pk = c.fk
AND c.foobar = 'somethingelse'
WHERE a.foo = 'something'
有人可以指出一些描述为什么会发生这种情况的文档吗?非常感谢
【问题讨论】:
标签: sql