Subquery Syntax
The syntax of a subquery is the same as that of a normal SELECT statement (see Chapters 4 through 7), except for the following differences:
You can nest a subquery in a SELECT, FROM, WHERE, or HAVING clause or in another subquery.
Always enclose a subquery in parentheses.
Don’t terminate a subquery with a semicolon. (You still must terminate the statement that contains the subquery with a semicolon.)
Don’t put an ORDER BY clause in a subquery. (A subquery returns an intermediate result that you never see, so sorting a subquery makes no sense.)
A subquery comprises a single SELECT statement. (You can’t use, say, a UNION of multiple SELECT statements as a subquery.)
A subquery can use columns in the tables listed in its own FROM clause ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access