Subqueries
A subquery is a special form of expression that is a query embedded within another query.Subqueries are written in the same way as regular SELECT
queries, but they must be enclosed in parentheses.Subquery expressions can be used in the following ways:
-
To specify an output column in the SELECT list
-
To obtain values or conditions for search predicates (the
WHERE
,HAVING
clauses). -
To produce a set that the enclosing query can select from, as though were a regular table or view.Subqueries like this appear in the
FROM
clause (derived tables) or in a Common Table Expression (CTE)