Database Reference
In-Depth Information
That covers different subquery types and the combinations thereof.
Now let's examine where subqueries can be used.
12.2
Where Can Subqueries Be Used?
Subqueries can be used almost anywhere in an SQL statement, in any SQL
command where an expression can be placed. Following are listed SQL
statement clauses in which a subquery can be placed:
SELECT clause.
WHERE clause.
ORDER BY clause.
FROM clause (Inline view).
VALUES clause of an INSERT statement.
UPDATE statement SET clause = (subquery).
CASE statement expression.
Function parameter.
The SPREADSHEET clause.
The next step is to look again at comparison conditions as described in
Chapters 5 and 7, except now exclusively as applied to subqueries.
12.3
Comparison Conditions and Subqueries
Many comparison conditions are applicable to subqueries. A subquery syn-
tax diagram is shown in Figure 12.1. The type of results allowed from a sub-
query depends on the comparison operator that you use. In Figure 12.1, the
highlighted operators require single-row subqueries. This includes the
equality and inequality operators (=, <=, >=, >, <, and !=), plus the LIKE
and BETWEEN operators. Other operators allow multiple rows to be
returned from the subquery. Multiple rows are allowed for the IN, NOT
IN, EXISTS, NOT EXISTS, plus equality operators combined with ANY,
SOME, or ALL.
We now know about different types of subqueries, where subqueries can
be used, and some basic comparison condition syntax for using subqueries.
 
Search WWH ::




Custom Search