What is the priority of multiple JOIN statements in SQLITE?

To my surprise, the following two queries returned different results:

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 imagine it doesn’t matter when you LEFT JOIN on zig, because I didn’t use the column of zig when joining bar and baz. However, it seems to be in the latter In, the JOIN-ing of bar and baz swallowed rows with null values ​​in zig… Why?

This works well. I was wrong.

To my surprise, the following two queries returned different results:

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 imagine it doesn’t matter when you LEFT JOIN on zig, because I didn’t use the column of zig when joining bar and baz. However, it seems that in the latter, the JOIN-ing of bar and baz is swallowed zig rows with null values… why?

This works well. I was wrong.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 895 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.