sqlite中多个JOIN语句的优先级是多少?(What is the precedence of multiple JOIN statements in sqlite?)

系统教程 行业动态 更新时间:2024-06-14 17:04:02
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.

更多推荐

本文发布于:2023-04-24 20:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/03a4ff3b13aba8ffb3e28e2d0b2dbb08.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   优先级   语句   JOIN   sqlite

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!