How does a LEFT JOIN keep the rows that have no match, and what does it put in the other table's columns?
A LEFT JOIN preserves every row from the left table. For each one, it looks for matching rows on the right; if there are matches, it produces one output row per match, and if there are none, it produces a single output row with NULLs in every column of the right table.
CREATE TABLE customers (
id INTEGER PRIMARY KEY,
name VARCHAR(120) NOT NULL
);
CREATE TABLE orders (
id INTEGER PRIMARY KEY,
customer_id INTEGER NOT NULL,
amount DECIMAL(10, 2) NOT NULL
);
INSERT INTO customers (id, name) VALUES
(1, 'Ada Lovelace'),
(2, 'Grace Hopper'),
(3, 'Alan Turing');
INSERT INTO orders (id, customer_id, amount) VALUES
(1, 1, 120.00),
(2, 1, 340.50),
(3, 2, 75.25);
SELECT c.id, c.name, o.id AS order_id, o.amount
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.id
ORDER BY c.id, o.id;Four rows come back. Ada Lovelace appears twice because she has two matching orders, Grace Hopper once, and Alan Turing once with NULL in the order_id and amount columns. Every customer survives; the missing order is represented as NULLs rather than as an absent row.
Two consequences of that design. The row count is no longer the number of left rows — a left row with three matches produces three output rows — so any aggregate applied afterwards counts joined rows, not left rows. And the NULLs are real NULLs, so every predicate you write against the right-hand columns has to account for them: WHERE o.amount > 100 silently drops the unmatched rows, and WHERE o.order_id IS NULL is the way to find the rows that found no partner at all.
Also worth knowing that the LEFT JOIN is not symmetric in how it treats the two sides. Keeping the left table's rows is the guarantee; the right table can lose rows. If you need the right side preserved, write it the other way round — FROM orders o LEFT JOIN customers c keeps every order and fills in the customer name where it is missing.