CHAPTER 14
Keeping all left table rows — even when there is no match.
🌟 Think of it this way: You have a list of all customers and a list of orders. A LEFT JOIN ensures every customer appears — even if they never placed an order. Missing orders will show as NULL.
Returns ALL rows from the left table (customers). Unmatched rows show NULL on the right side.
SQL
SELECT c.name, o.order_id, o.total FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id ORDER BY c.name;
Classic LEFT JOIN + IS NULL patter
SELECT c.name FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id WHERE o.order_id IS NULL;
✅ Pro Tips: This pattern — LEFT JOIN + WHERE right_side IS NULL — is one of the most frequently used patterns in analytics. 'Users who signed up but never purchased', 'products never sold', 'employees not assigned to any project'.
✅ Pro Tip: LEFT JOIN + IS NULL is widely used to find missing data — like users who never logged in, customers with no orders, or products that were never sold.
| customer_id | name | city | country |
|---|---|---|---|
| 1 | Ananya | Hyderabad | India |
| 2 | Rohan | Bangalore | India |
| 3 | Sam | Mumbai | India |
| 4 | Lisa | London | UK |
| 5 | Ravi | Delhi | India |
| order_id | customer_id | order_date | total | status |
|---|---|---|---|---|
| 1 | 1 | 2024-01-15 | 79999 | completed |
| 2 | 2 | 2024-01-20 | 3498 | completed |
| 3 | 1 | 2024-02-10 | 65000 | completed |
| 4 | 3 | 2024-02-14 | 499 | pending |
| 5 | 2 | 2024-03-01 | 248 | completed |
| 6 | 5 | 2024-03-15 | 2999 | shipped |
| 7 | 1 | 2024-04-05 | 149 | completed |