November 2003
Intermediate to advanced
816 pages
14h 53m
English
A subquery is a SELECT statement inside parentheses within another DML statement. It can be in INSERT, UPDATE, DELETE or SELECT statement. It is always enclosed in parentheses (). The ability to use a query within a query was the original reason for the word structured in the name Structured Query Language.[1]
[1] Groff 1999, p. 218.
The result of a SELECT is a virtual table called a result set.
As shown in Table B-5, there are four result set sizes which are useful when discussing subqueries.
| 1. INSERT INTO table SELECT ... | -- target table must exist |
| Subquery Result Set Dimensions | Result Set Name | Example |
|---|---|---|
| 1 X 1 | Scalar | ( SELECT AVG(salary) FROM emps3 ) ( SELECT SUM(order_amt) FROM orders WHERE custid = 11) |
Read now
Unlock full access