Download Informix Guide to SQL: Tutorial

Transcript
Single-Valued Subqueries
Query Result 3-28
order_num
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
Single-Valued Subqueries
You do not need to include the keyword ALL or ANY if you know the
subquery can return exactly one value to the outer-level query. A subquery that
returns exactly one value can be treated like a function. This kind of subquery
often uses an aggregate function because aggregate functions always return
single values
Query 3-29 uses the aggregate function MAX in a subquery to find the
order_num for orders that include the maximum number of volleyball nets.
Query 3-29
SELECT order_num FROM items
WHERE stock_num = 9
AND quantity =
(SELECT MAX (quantity)
FROM items
WHERE stock_num = 9)
order_num
1012
3-32
Informix Guide to SQL: Tutorial
Query Result 3-29