1 / 8

PostgreSQL · Joins & aggregations

Keep the left side

LEFT JOIN returns every left-side row. When a left row has no right-side match, the right-side columns are filled with NULLs. This is useful for questions such as “which customers have not placed an order?”

SELECT c.id, o.id AS order_id
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.id;

If a customer has two orders, that customer still appears twice. Outer joins preserve unmatched rows; they do not change one-to-many cardinality.