SQL Reference

Quantified Predicate

>>-+-expression1--+- = -------+---+-SOME-+---(fullselect1)------+->
   |              |      (1)  |   +-ANY--+                      |
   |              +- <> ------+   '-ALL--'                      |
   |              +- < -------+                                 |
   |              +- > -------+                                 |
   |              +- <= ------+                                 |
   |              '- >= ------'                                 |
   |    .-,----------------.                                    |
   |    V                  |                                    |
   '-(------expression2----+---)-- = --+-SOME-+---(fullselect2)-'
                                       '-ANY--'
 
>--------------------------------------------------------------><
 

Notes:

  1. Other comparison operators are also supported 38.

A quantified predicate compares a value or values with a collection of values.

The fullselect must identify a number of columns that is the same as the number of expressions specified to the left of the predicate operator (SQLSTATE 428C4). The fullselect may return any number of rows.

When ALL is specified:

When SOME or ANY is specified:

Examples: Use the following tables when referring to the following examples.

Figure 10.

Example Tables for Quantified Predicate

Example 1

  SELECT COLA FROM TBLAB 
     WHERE COLA = ANY(SELECT COLX FROM TBLXY)

Results in 2,3. The subselect returns (2,3). COLA in rows 2 and 3 equals at least one of these values.

Example 2

  SELECT COLA FROM TBLAB 
     WHERE COLA > ANY(SELECT COLX FROM TBLXY)

Results in 3,4. The subselect returns (2,3). COLA in rows 3 and 4 is greater than at least one of these values.

Example 3

  SELECT COLA FROM TBLAB 
     WHERE COLA > ALL(SELECT COLX FROM TBLXY)

Results in 4. The subselect returns (2,3). COLA in row 4 is the only one that is greater than both these values.

Example 4

  SELECT COLA FROM TBLAB 
     WHERE COLA > ALL(SELECT COLX FROM TBLXY
                         WHERE COLX<0)

Results in 1,2,3,4, null. The subselect returns no values. Thus, the predicate is true for all rows in TBLAB.

Example 5

SELECT * FROM TBLAB 
   WHERE (COLA,COLB+10) = SOME (SELECT COLX, COLY FROM TBLXY)

The subselect returns all entries from TBLXY. The predicate is true for the subselect, hence the result is as follows:

COLA        COLB       
----------- -----------
          2          12
          3          13
 
 

Example 6

SELECT * FROM TBLAB 
   WHERE (COLA,COLB) = ANY (SELECT COLX,COLY-10 FROM TBLXY)

The subselect returns COLX and COLY-10 from TBLXY. The predicate is true for the subselect, hence the result is as follows:

COLA        COLB       
----------- -----------
          2          12
          3          13
 


[ Top of Page | Previous Page | Next Page ]