LEFT JOIN
Keep all rows from the left table
✅ What You Will Learn
LEFT JOIN returns all rows from the left (first) table, and the matching rows from the right table. If there is no match in the right table, the right table columns come back as NULL.
This is the second most used JOIN in analytics. Use it when you want to keep all records from your main table even if some do not have matching records in the second table — for example, showing all customers including those who have never placed an order.
📋 LEFT JOIN: all customers kept — Amit has no orders (NULL shown)
| customer_id | customer_name | city | order_id | product | amount |
|---|---|---|---|---|---|
| 1 | Rahul Sharma | Delhi | 1001 | Laptop | 45000 |
| 2 | Priya Verma | Noida | 1002 | Mobile Phone | 18000 |
| 3 | Amit Kumar | Gurgaon | NULL | NULL | NULL |
| 4 | Sneha Kapoor | Delhi | 1004 | Laptop | 52000 |
| 5 | Vikram Singh | Noida | 1005 | Tablet | 28000 |
Syntax
Examples
📌 Key Points to Remember
- ✓LEFT JOIN keeps ALL rows from the left table
- ✓Unmatched rows from the right table show NULL in those columns
- ✓The "left" table is the one after FROM, the "right" table is after JOIN
- ✓Use LEFT JOIN + IS NULL to find records with no match
- ✓LEFT JOIN is used more often than INNER JOIN in most reporting scenarios
🏢 Real-World Application
LEFT JOIN is critical for finding gaps in data. "Show all customers and how much they spent — including customers who have never placed an order" — that is a LEFT JOIN with customers on the left. Customers with no orders get NULL for the order columns. A common analytics pattern is LEFT JOIN + WHERE right_table.id IS NULL — this finds all customers who have never ordered, users who never logged in, or products that have never been sold. This "anti-join" is used everywhere in churn analysis, retention reporting, and gap analysis.
⚠️ Common Mistakes to Avoid
❓ Frequently Asked Questions
What is LEFT JOIN in SQL?
LEFT JOIN returns all rows from the left (first) table and matching rows from the right (second) table. When there is no match in the right table, the right-table columns appear as NULL in the result.
When should I use LEFT JOIN instead of INNER JOIN?
Use LEFT JOIN when you want to keep all rows from the left table even if they have no match on the right. Use INNER JOIN when you only want rows that have matches in both tables.
What is the anti-join pattern in SQL?
An anti-join finds rows in the left table that have no match in the right table. Use LEFT JOIN and then filter WHERE right_table.id IS NULL. This is how you find customers with no orders, products with no sales, etc.
Is LEFT JOIN the same as LEFT OUTER JOIN?
Yes. LEFT JOIN and LEFT OUTER JOIN are identical — OUTER is optional. Both return all rows from the left table with NULLs for unmatched right table columns.
How does LEFT JOIN handle multiple matches?
If the right table has multiple rows matching one left-table row, the left-table row is duplicated once per match, just like INNER JOIN. For example, one customer with three orders will appear three times.
✏️ Practice Exercise
Using LEFT JOIN, write a query to show all customers and their total spend. Customers with no orders should show 0 as their total (hint: use COALESCE to replace NULL with 0).
Learn SQL with Live Trainer Guidance
These tutorials give you the theory. Our live SQL course at EVIKA Academy, Noida teaches you to apply SQL on real company datasets — with a trainer who uses it daily at MakeMyTrip.