When you create a query, you use WHERE and HAVING clauses to restrict the rows that the query returns.
Sometimes, the rows you select depend on information stored in more than one table. A subquery in the WHERE or HAVING clause allows you to select rows from one table according to specifications obtained from another table. Additional ways to do this can be found in Joins: Retrieving Data from Several Tables.
This subquery chapter assumes some knowledge of queries and the syntax of the select statement. Information about queries appears in Queries: Selecting Data from a Table.
Introduction to subqueries
Using subqueries in the WHERE clause
Subqueries in the HAVING clause
Subquery comparison test
Quantified comparison tests with ANY and ALL
Testing set membership with IN conditions
Existence test
Outer references
Subqueries and joins
Nested subqueries
How subqueries work