Subqueries
Same barkada food-trip bill from Episode 9, plus a new friends table. Covers subqueries — a SELECT nested inside another query — so you can answer questions like “which item costs the most?” without hardcoding the answer.
How it works
A subquery is just a SELECT that runs first and hands its single answer to the outer query, as if you'd typed the result in by hand. Here, (SELECT MAX(price) FROM orders) runs once and resolves to a single number — the highest price in the whole table. The outer query then asks: “which row's price equals that number?”
This is different from sorting and grabbing the top row with ORDER BY price DESC LIMIT 1, which also finds the one biggest item — but that trick breaks the moment you need the biggest item per group instead (e.g. the most expensive item in each category). That's where correlated subqueries take over, in a later episode.
The friends table isn't needed for this challenge — it's here so Episode 11 can introduce joins using the same dataset.
Show the solution
SELECT item, price
FROM orders
WHERE price = (SELECT MAX(price) FROM orders);
Result: Fried Chicken at ₱120 — the single most expensive item Ana ordered.