LEFT JOIN
Preserve every row on the left, even when the right side has no match: null-fill the right-side columns. Most analytics queries that want "users and whether they bought something" need a LEFT JOIN, not INNER JOIN, because they need the non-buyers in the result too.
Syntax #
sql
SELECT a.id, b.value_col
FROM a
LEFT JOIN b ON a.key = b.key;Example #
Loading SQL editor...
Warning
Filtering right-side columns in WHERE silently downgrades to INNER JOIN. NULL = anything is NULL, so WHERE o.status = 'paid' excludes every user whose order didn't match (including users with no orders at all). Put right-side filters inside the ON clause: LEFT JOIN orders AS o ON o.user_id = u.id AND o.status = 'paid'.