On Tue, 2024-11-19 at 14:30 +0100, Moreno Andreo wrote:
> Inhttps://www.cybertec-postgresql.com/en/join-strategies-and-performance-in-postgresql/
> you say
> "Note that for inner joins there is no distinction between the join condition and the WHERE condition, but that
doesn'thold for outer joins."
> What do you mean?
CREATE TABLE a (id integer);
INSERT INTO a VALUES (1), (2), (3);
CREATE TABLE b (id integer);
INSERT INTO b VALUES (1), (2), (4);
SELECT * FROM a JOIN b ON a.id = b.id AND b.id < 2;
id │ id
════╪════
1 │ 1
(1 row)
SELECT * FROM a JOIN b ON a.id = b.id WHERE b.id < 2;
id │ id
════╪════
1 │ 1
(1 row)
SELECT * FROM a LEFT JOIN b ON a.id = b.id AND b.id < 2;
id │ id
════╪════
1 │ 1
2 │ ∅
3 │ ∅
(3 rows)
SELECT * FROM a LEFT JOIN b ON a.id = b.id WHERE b.id < 2;
id │ id
════╪════
1 │ 1
(1 row)
Yours,
Laurenz Albe