By specifying a quantity
predicate, you can compare a value or list of values to a set of values or value lists.Syntax
<quantified_predicate> ::=
<expression> <comp_op> <quantifier> <expression_list>
| <expression> <comp_op> <quantifier> <subquery>
| <expression_list> <equal_or_not> <quantifier> (<expression_list>,...)
| <expression_list> <equal_or_not> <quantifier> <subquery>
The following operators are available for comparing values:
<, >, <>, !=, =, <=, >= (
Value lists can only be compared with the = and <> operators (
equal_or_not).The quantified predicate can be qualified with ALL, SOME, or ANY (
quantifier).Explanation
The subquery must supply a result table (see
result table name) that contains the same number of columns as the number of values specified by the expression or expression list on the left-hand side of the operator.Each list of values specified to the right of the
equal_or_not operator ( expression_list ) must contain the same number of values as specified in the value list in front of the equal_or_not operator.The entry '------' in the list below means that no statement can be made if only the result of the comparison with one s is known.
x <compare> <quantifier> S, whereby compare ::= comp_op | equal_or_not
quantifier ::= ALL |
quantifier ::= ANY | SOME | |
S is empty |
true |
false |
x <compare> S is true for at least one s from S |
------ |
true |
x <compare> S is true for all s from S |
true |
true |
x <compare> S is not false for any value from S and is undefined for at least one value s |
undefined |
|
S contains NULL values and x <compare> S is true for all other s |
undefined |
true |
x <compare> S is false for at least one value s from S |
false |
------ |
x <compare> S is false for all s from S |
false |
false |
x <compare> S is not true for any value s from S and is undefined for at least one value s |
undefined | |
S contains NULL values and x <compare> S is false for all other s |
false |
undefined |
Model table:
List of hotels that have the same name as other cities in the base table.
SELECT name, city FROM hotel
WHERE name = ANY (SELECT city FROM hotel)
The subquery
SELECT city FROM hotel determines the list of city names that are compared with the hotel names.