⬅️ 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)
orders (Right Table)
📄 LEFT JOIN Example
SELECT c.name, o.order_id
FROM customers c
LEFT JOIN orders o
ON c.customer_id = o.customer_id;
Result
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:
- WHERE runs 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
