CodeRigor

LEARN BY DOING

SQL joins & NULL explorer

Follow real rows through INNER and LEFT joins. Move a predicate between ON and WHERE and see what changes.

Customers

row_ididname
11Ada
22Ben
33Cy
4NULLNo ID

Orders

idcustomer_idtotal
A120
B180
CNULL100
D440

Follow the query

SQL
SELECT c.name, o.id, o.total
FROM customers AS c
LEFT JOIN orders AS o
  ON c.id = o.customer_id
ORDER BY c.row_id, o.id;

5 result rows

nameorder idtotal
AdaA20
AdaB80
BenNULLNULL
CyNULLNULL
No IDNULLNULL

NULL equality does not produce a match, including NULL against NULL. Ada has two matching orders. A LEFT join supplies NULLs for unmatched customers; a WHERE comparison then filters those NULL-extended rows out. An ON predicate changes matching before unmatched rows are supplied.