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?
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.