Chapter 8. Subqueries
To this point, I've used a single SELECT
statement to retrieve data from one or more tables. This chapter describes nested queries, which let you retrieve or modify data based on another query's result.
A subquery, or subselect, is a SELECT
statement embedded in another SQL statement. You can nest a subquery in:
The
SELECT
,FROM
,WHERE
, orHAVING
clause of aSELECT
statementAnother subquery
An
INSERT
,UPDATE
, orDELETE
statement
In general, you can use a subquery anywhere an expression is allowed, but your DBMS might restrict where they can appear. This chapter covers subqueries nested in a SELECT
statement or another subquery; Chapter 10 covers subqueries embedded in INSERT
, UPDATE
, and DELETE
statements.
Understanding Subqueries ...
Get SQL: Visual Quickstart Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.