Using Subquery in FROM Clause (Derived Table)
📖 Scenario: You work for a small bookstore that keeps track of book sales. You have a table called sales that records each sale with the book's book_id and the quantity sold.Your manager wants to see the total quantity sold for each book, but only for books that sold more than 10 copies in total.
🎯 Goal: Create a SQL query that uses a subquery in the FROM clause (a derived table) to calculate total sales per book, then filters to show only books with total sales greater than 10.
📋 What You'll Learn
Create a table called
sales with columns book_id and quantity.Insert the exact sales data provided.
Write a subquery in the
FROM clause that sums quantity per book_id.Filter the results to show only books with total quantity sold greater than 10.
💡 Why This Matters
🌍 Real World
Derived tables help organize complex queries by breaking them into smaller parts, making it easier to analyze grouped data like sales totals.
💼 Career
Knowing how to use subqueries in the FROM clause is useful for data analysts and developers who write reports or dashboards that summarize data.
Progress0 / 4 steps