SQL sub-select (subquery)
A sub-select is a SELECT inside brackets in a WHERE clause. It runs first and its result is used by the outer query, e.g. to compare with an AVG or to match values using IN.
Understanding SQL sub-select (subquery) in QCE Digital Solutions Unit 4
What it does: The inner SELECT runs first and returns one value (the maximum price). The outer query uses = to compare each price with that value. A sub-select is a complete SELECT written inside brackets within the WHERE clause. It is not a separate statement. The sub-select must be wrapped in brackets. Without the brackets the query is a syntax error. Sub-selects supply a value or list that is calculated from the data, such as an average. Sorting is done by ORDER BY. IN checks each row against the list of values returned by the sub-select, so only students who have placed an order match.
Common mistakes: A sub-select must be wrapped in brackets. The opening bracket is missing, so the line should be WHERE price > (SELECT. The sub-select returns a list of many productId values. = only compares with one value, so it should be WHERE productId IN.
Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.
This module's key terms are also in a printable crossword (Modules 334–401) and word search (Modules 127–401).
Take this worksheet further — free with Cloodit
Each concept is reinforced from every angle — learned, then applied, then tested.
Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.
Over 100 of them, across seven natural biomes.
Turns their work into revision material ready for Flash Cards and Exam study.
Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.
Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.
Quick Questions
Match the Pairs
Key Term
(SELECT ...)Fill in the Blanks
Spot the Error
Student with a class code? Join your class →