Using Scalar Subqueries in MySQL
📖 Scenario: You are managing a small bookstore database. You want to find out the price of the most expensive book in each category and display it alongside the category name.
🎯 Goal: Build a MySQL query using scalar subqueries to show each book category with the highest book price in that category.
📋 What You'll Learn
Create a table called
books with columns id (integer), title (varchar), category (varchar), and price (decimal).Insert at least 5 rows with different categories and prices.
Write a scalar subquery to find the maximum price for each category.
Select the category and the maximum price using the scalar subquery.
💡 Why This Matters
🌍 Real World
Scalar subqueries help you get single values from related data, like finding max prices per category in a bookstore.
💼 Career
Database developers and analysts often use scalar subqueries to write efficient queries that summarize or compare data within groups.
Progress0 / 4 steps