Blog · Guide

SQL Subqueries Explained: A Query Inside a Query

Use a subquery to compare each row to a calculated value — like products priced above the average.

customers first_name last_name city result first_name · city
SELECT chooses which columns appear in the result.

Compare to a calculated number

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

The inner query runs as its own question; the outer query uses that answer. Start with scalar (one-value) subqueries before diving into IN-lists.

Try it yourself

The fastest way to lock this in is a short drill on the same Northstar Market tables.

Practice a subquery

Related guides