📝 What You’ll Learn

  • What LEFT JOIN means
  • Syntax and usage
  • Examples of real-world queries
  • Difference from INNER JOIN

🧭 What Is LEFT JOIN?

LEFT JOIN returns:

  • ✅ All rows from the left table
  • ✅ Matching rows from the right table
  • NULL if there's no match on the right

It’s useful when you want to keep all data from the first table, even if there’s nothing related in the second one.

🧱 LEFT JOIN Syntax

SELECT columns
FROM table1
LEFT JOIN table2
ON table1.column = table2.column;

🧪 Example: Users and Orders

SELECT users.name, orders.amount
FROM users
LEFT JOIN orders
ON users.id = orders.user_id;

This query will show all users, even those who haven’t placed any orders.
Users without orders will show NULL for orders.amount.

🧪 Example: Products and Reviews

SELECT products.name, reviews.rating
FROM products
LEFT JOIN reviews
ON products.id = reviews.product_id;

Useful for listing every product, whether it has reviews or not.

⚖️ INNER vs LEFT JOIN

Feature INNER JOIN LEFT JOIN
Returns Matches ✅ Yes ✅ Yes
Keeps Non-Matches ❌ No ✅ From left table

📘 Recap

  • LEFT JOIN includes all left table rows, with matches (or NULLs) from the right
  • Great for showing "all items, even if unused"
  • Helps identify missing or unmatched data