The LEFT JOIN
A LEFT JOIN returns all records from the left table (Users), and the matched records from the right table (Orders).
If there is no match, the result is NULL on the right side.
Visual Demo:
Look at the visualization panel on the right. It shows how:
- Alice matches 2 orders.
- Bob matches 1 order.
- Charlie has no orders, so he gets a
NULL.
SELECT users.name, orders.item
FROM users
LEFT JOIN orders ON users.id = orders.user_id;
Task:
Run the query to see the actual results match the animation!