Memra

LEFT JOIN: keeping unmatched rows

Keep every row on the left, matched or not.

Keep the left side

An INNER JOIN drops rows with no match. A LEFT JOIN keeps every row from the left table; where there's no match on the right, the right columns come back NULL.

That makes it the tool for "find the things with nothing attached". Customers who have never ordered:

SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.id IS NULL;

The WHERE ... IS NULL keeps only the customers whose left join found no order.

NORMAL ~/memra/learn/postgresql/left-join utf-8 LF