我正在检查报告中的一些数据错误,我遇到了左连接的问题。
我尝试将查询重写为非常简单的原理图代码。第一个查询返回'foo',第二个没有。唯一的区别仅在于on条件,两个选择都应返回零线。谢谢你,马丁
SELECT 'foo'
FROM
(SELECT
'A' AS a,
'B' AS b) X
LEFT JOIN
(SELECT
'C' AS a,
'B' AS b) Y
ON X.a = Y.a AND X.b = Y.b
WHERE Y.b IS NOT NULL;
SELECT 'bar'
FROM
(SELECT
'A' AS a,
'B' AS b) X
LEFT JOIN
(SELECT
'C' AS a,
'B' AS b) Y
ON X.a = Y.a
WHERE Y.b IS NOT NULL;