Lesson 13 / 28
LEFT & RIGHT JOIN
Keep unmatched rows from one side of the join.
LEFT JOIN
LEFT JOIN keeps every row from the left table, filling unmatched right-side columns with NULL.
SELECT c.name, o.id AS order_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id;
Output:
name | order_id Asha Rao | 1 Rahul Mehta | 2 Priya Nair | NULL
RIGHT JOIN
RIGHT JOIN is the mirror of LEFT JOIN — it keeps every row from the right table instead. Most people just swap table order and use LEFT JOIN.
Finding unmatched rows
Add WHERE o.id IS NULL after a LEFT JOIN to find customers with no orders at all.