sqlite中多个JOIN语句的优先级是多少?(What is the precedence of multiple JOIN statements in sqlite?)
以下两个查询返回不同的结果,令我惊讶的是:
SELECT * FROM foo JOIN bar ON bar.id=foo.bar_id JOIN baz ON baz.id=foo.baz_id LEFT JOIN zig ON zig.foo_id=foo.id;和:
SELECT * FROM foo LEFT JOIN zig ON zig.foo_id=foo.id JOIN bar ON bar.id=foo.bar_id JOIN baz ON baz.id=foo.baz_id;我想象你在LEFT JOIN zig时不要紧,因为我在加入bar和baz时没有使用zig的列。 然而,在后者看来, bar和baz的JOIN -ing会吞噬zig具有null值的那些行......为什么是这样呢?
The following two queries are returning different results, to my surprise:
SELECT * FROM foo JOIN bar ON bar.id=foo.bar_id JOIN baz ON baz.id=foo.baz_id LEFT JOIN zig ON zig.foo_id=foo.id;and:
SELECT * FROM foo LEFT JOIN zig ON zig.foo_id=foo.id JOIN bar ON bar.id=foo.bar_id JOIN baz ON baz.id=foo.baz_id;I'm imagining that it shouldn't matter when you LEFT JOIN on zig, since I'm not using zig's columns when joining the bar and baz. However, it appears that in the latter, the JOIN-ing of bar and baz swallows up the rows where zig had null values... why is that?
最满意答案
这工作正常。 我错了。
This works fine. I was wrong.
更多推荐
发布评论