LEFT JOIN — Complete Guide
LEFT JOIN — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.
On this page
MySQL Tutorial · Lesson 22 of 100
LEFT JOIN
Basics → Advanced
Basics · 1 — SQL · ~6 min · MySQL — Joins & Relationships
What is this?
LEFT JOIN keeps every row from the left table and fills NULLs where the right table has no match. Right-only rows are dropped.
Why should you care?
Marketing wants all customers including those who never ordered — find inactive users for win-back SMS.
See it live — copy this example
Run in MySQL Workbench or the mysql CLI.
SELECT c.full_name, o.order_id, o.total_inr
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL;
What happened?
- All customers appear on the left.
- WHERE o.order_id IS NULL keeps only customers with no matching order — the “never purchased” cohort.
Practice next
- Ensure some customers have zero orders.
- Run query; list names with NULL order columns.
- Remove WHERE to see all customers with repeated rows per order.
- Move total_inr filter into ON clause and compare results.
- Count never-ordered users with SELECT COUNT(*) FROM (...).
Remember
LEFT JOIN preserves left-side rows. IS NULL on right PK finds non-matches. Watch WHERE filters that nullify outer join intent.
DataFlow win-back campaign
CRM exports customers with NULL orders for Diwali coupon blast.
Outcome: Reactivation revenue without spamming active buyers.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!