According to this SQL join cheat-sheet, a left outer join on one column is the following :
SELECT *
FROM a
LEFT JOIN b
ON a.foo = b.foo
WHERE b.foo IS NULL
I'm wondering what it would look like with a join on multiple columns, should it be an OR
or an AND
in the WHERE
clause ?
SELECT *
FROM a
LEFT JOIN b
ON a.foo = b.foo
AND a.bar = b.bar
AND a.ter = b.ter
WHERE b.foo IS NULL
OR b.bar IS NULL
OR b.ter IS NULL
or
SELECT *
FROM a
LEFT JOIN b
ON a.foo = b.foo
AND a.bar = b.bar
AND a.ter = b.ter
WHERE b.foo IS NULL
AND b.bar IS NULL
AND b.ter IS NULL
?
(I don't think it does, but in case it matters, the db engine is Vertica's)
(I'm betting on the OR
one)