Video in progress
When do you need FULL OUTER JOIN and CROSS JOIN?
FULL OUTER JOIN returns all rows from both tables and fills the side with no match with NULL, which is handy when comparing two lists. CROSS JOIN pairs every row with every other (a Cartesian product), and is used to generate combinations.
📖 Answer
A real use of FULL OUTER JOIN is reconciliation. For example, our payments against the report from the bank:
SELECT p.external_id AS bizda, b.tx_id AS bankda, p.amount, b.amount
FROM payments p
FULL OUTER JOIN bank_statement b ON b.tx_id = p.external_id
WHERE p.external_id IS NULL -- in the bank's data, not in ours
OR b.tx_id IS NULL -- in ours, not in the bank's
OR p.amount <> b.amount; -- the amounts differ
CROSS JOIN is useful, for example, to list every store for every day, even the days with no sales:
SELECT d.day, s.id AS store_id
FROM generate_series('2026-11-01'::date, '2026-11-30', interval '1 day') AS d(day)
CROSS JOIN stores s;
Then you LEFT JOIN the sales onto this "grid", and the empty days show up as 0.
Be careful with CROSS JOIN: 10,000 × 10,000 = 100 million rows. The same thing happens if you forget the JOIN condition and write two tables separated by a comma (FROM a, b).
Sign up to mark studied questions and save your progress.