Using Correlated Subqueries in MySQL
📖 Scenario: You are managing a small online bookstore database. You want to find books that have a price higher than the average price of books in the same category.
🎯 Goal: Build a MySQL query using a correlated subquery to list all books with prices above the average price of their category.
📋 What You'll Learn
Create a table called
books with columns id, title, category, and price.Insert the exact data rows provided into the
books table.Write a correlated subquery that calculates the average price per category.
Select books where the price is greater than the average price of their category.
💡 Why This Matters
🌍 Real World
Correlated subqueries help compare each row to a group of related rows, useful in sales, inventory, and reporting databases.
💼 Career
Understanding correlated subqueries is important for database analysts and developers to write efficient and meaningful queries.
Progress0 / 4 steps