skip to today's puzzle

A query can hold another query inside it

A query in parentheses hands its answer to the bigger query around it. The inner query runs first. Here it finds the average menu price, and the outer query keeps items priced above it.

A tiny example

In plain English: Show me the menu items that cost more than the average menu price.

SELECT name, price
FROM menu_items
WHERE price > (
  SELECT AVG(price)
  FROM menu_items
);

Query result

nameprice
Brunch plate9.50
Pour-over6.00

The inner query works out an average price of 5.00, and these are the two menu items priced above it.

Related SQL lessons

Ready for a break?

A fresh, bite-sized SQL puzzle waits every morning. Tap tiles, see real results. No terminal, no setup, no timers.

Try today's free SQL puzzle