Using Subqueries in the FROM Clause (Derived Tables) in MySQL
📖 Scenario: You work for a small online bookstore. You have a table called sales that records each book sale with the book's title, author, and the copies_sold for that sale.Your manager wants to see the total copies sold per author, but only for authors who sold more than 100 copies in total.
🎯 Goal: Build a MySQL query that uses a subquery in the FROM clause (a derived table) to calculate total copies sold per author, then filters authors with total sales greater than 100.
📋 What You'll Learn
Use a subquery in the
FROM clause to calculate total copies sold per author.Name the subquery result as
author_sales.Select
author and total_copies from the derived table.Filter results to show only authors with
total_copies greater than 100.💡 Why This Matters
🌍 Real World
Derived tables help break complex queries into manageable parts, making it easier to analyze grouped or aggregated data before applying filters or sorting.
💼 Career
Understanding subqueries in the FROM clause is essential for data analysts and developers to write efficient and readable SQL queries for reporting and data processing.
Progress0 / 4 steps