Finding unmatched rows with LEFT JOIN
📖 Scenario: You work at a small bookstore. You have two tables: books and sales. The books table lists all books in the store. The sales table records which books have been sold.You want to find books that have never been sold yet.
🎯 Goal: Create a SQL query that finds all books from the books table that do not have matching entries in the sales table using a LEFT JOIN.
📋 What You'll Learn
Create a
books table with columns book_id and title and insert 3 books with IDs 1, 2, 3 and titles 'Book A', 'Book B', 'Book C'.Create a
sales table with columns sale_id and book_id and insert 2 sales for books 1 and 2.Write a
LEFT JOIN query joining books and sales on book_id.Filter the results to show only books with no matching sales (unmatched rows).
💡 Why This Matters
🌍 Real World
Finding unmatched rows is useful in real life to identify missing or incomplete data, such as customers who never made a purchase or products never sold.
💼 Career
Database developers and analysts often use LEFT JOIN with NULL filtering to find gaps in data, which helps in reporting, data cleaning, and business decisions.
Progress0 / 4 steps