liveBook · Manning

Subquery

A subquery is a query embedded within another query or statement whose result contributes to evaluating the containing operation.

How 2 Manning books explain it

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 subquery →

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.

Read how DuckDB in Action explains subquery →

Also covered in

What to know first

Related concepts

Questions about subquery

What is subquery?

A subquery is a query embedded within another query or statement whose result contributes to evaluating the containing operation.

Which Manning books explain subquery?

Learn SQL in a Month of Lunches and DuckDB in Action.

What should I know before learning subquery?

Manning books that teach subquery usually introduce SQL, data warehouse, performance and where clause first.

What is the difference between subquery and join?

A subquery is a query embedded within another query or statement whose result contributes to evaluating the containing operation. A join is an operation that combines records or data elements from multiple inputs according to matching or related values or conditions.

What is subquery part of?

Subquery is part of from clause. 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.