Nested query
A nested query is a query embedded within another query or statement whose result participates in evaluating the containing operation.
Learn SQL in a Month of Lunches
A subquery is an SQL query nested within another SQL statement whose result can supply data for joining, filtering, or other operations.
- How it is used
- Combines multiple SELECT results into one statement for filtering, comparisons, and joins.
- How deep it goes
- Demonstrates WHERE, FROM, and SELECT placements plus multirow operators, while warning that SELECT-clause subqueries are rarely best.
- Examples
- Uses customer orders, titles in order 1034, Joe Pagenaud, Cora Daly, and the longest title name.
- What you can do after
- Apply it via SQL operators to filter, exclude, compare, and join results returned by nested SELECT statements.
Read how Learn SQL in a Month of Lunches explains nested query →
DuckDB in Action
A subquery is a query nested inside another SQL statement or expression.
- How it is used
- Stages analytical computations, filters rows against inner results, and prepares values for comparisons.
- How deep it goes
- Explains uncorrelated, scalar, correlated, and set-comparison forms with runnable examples, while deferring broader query optimization.
- Examples
- Demonstrates per-system power aggregation, maximum-reading filters, correlated maxima, joins, EXISTS, IN, ANY, and ALL.
- What you can do after
- Apply it in DuckDB to stage aggregates, filter by scalar results, correlate inner queries, and test membership or inequality across result sets.
Related concepts
- joinalternative to · A join is an operation that combines records or rows from multiple data sources according to specified matching conditions or relationships.
- NOT INused by · NOT IN is a SQL predicate that tests whether a value is absent from a specified list or subquery result, subject to null semantics.
- temporary tablealternative to · A temporary table is a database table created for transient use during a session or operation and removed automatically or explicitly when its relevant scope ends.
- membership operatoruses · A membership operator is a language construct that tests whether a specified value or property is present in a supported collection, range, or object.
- from clausepart of · A FROM clause is the SQL query component that specifies the tables or other data sources providing input rows.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

