We use analytics and advertising cookies to understand how the site is used and whether our ads on Facebook and Instagram work. They are set only if you accept. See our Privacy Policy for details.
A subquery is a query nested inside another - either evaluated once (scalar, e.g. comparing against a global average) or re-evaluated per outer row (correlated). Interviews use them for "above their own group's average" problems, which test whether you can reason about row-by-row evaluation rather than pattern-matching syntax. They're also the stepping stone to CTEs and window functions, which often express the same idea more cleanly.
5 problems across 4 schemas · Premium. Each runs your query in an isolated SQLite sandbox with instant, graded feedback.
A quick data question to warm up before you write SQL. No signup needed.
Product data arrives in three normalised source tables: product, subcategory and category. The reporting model needs a single product dimension, and a product's category history must be kept when it changes. How should the data be prepared?
Keep the syntax at your fingertips with the free SQL quick references, then come back and solve.