Understanding Why Outer Joins Are Needed
📖 Scenario: You work at a small bookstore. You have two tables: one with books and another with sales. Some books have sales records, but some do not because they haven't been sold yet.
🎯 Goal: Build a query that shows all books and their sales if any. If a book has no sales, it should still appear in the list with a NULL for sales. This will help the store owner see which books have not sold yet.
📋 What You'll Learn
Create a
books table with columns book_id and title.Create a
sales table with columns sale_id, book_id, and quantity.Insert exact data into both tables as specified.
Write a query using a LEFT OUTER JOIN to list all books with their sales quantities if available.
Ensure books without sales still appear with
NULL in the sales columns.💡 Why This Matters
🌍 Real World
Bookstores and many businesses need to see all items in inventory even if they have no sales yet. Outer joins help show this complete picture.
💼 Career
Understanding outer joins is essential for data analysts and database developers to write queries that handle missing or incomplete data gracefully.
Progress0 / 4 steps