⬅️ LEFT JOIN in SQL
Last Updated: 7th January 2026
The LEFT JOIN returns all rows from the left table and matching rows from the right table.
- If there is no match, columns from the right table become
NULL. - Left table → always preserved
- Right table → included only if matched
Hinglish Tip 🗣: Left table ka poora data chahiye, match ho ya na ho →
LEFT JOIN.
🧾 Basic Syntax
SELECT columns
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;
📄 Example Tables (Mental Model)
customers (Left Table)
| customer_id | name |
|---|---|
| 1 | Rahul |
| 2 | Anjali |
| 3 | Aman |
orders (Right Table)
| order_id | customer_id |
|---|---|
| 101 | 1 |
| 102 | 3 |
📄 LEFT JOIN Example
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id;
✅ Result
| name | order_id |
|---|---|
| Rahul | 101 |
| Anjali | NULL |
| Aman | 102 |
Explanation:
- Rahul → has order → shown
- Anjali → no order → still shown (
NULL) - Aman → has order → shown
🚫 WHERE vs ON (Very Important)
❌ This breaks LEFT JOIN logic:
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_id IS NOT NULL;
✔ Correct way (when filtering right table):
LEFT JOIN orders o
ON c.customer_id = o.customer_id
AND o.order_id IS NOT NULL;
Reason:
WHEREruns after JOIN- It can turn LEFT JOIN into INNER JOIN accidentally
🔄 LEFT JOIN + WHERE
SELECT c.name
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
✔ Finds customers with no orders