A comparison predicate specifies a comparison between two values or lists of values.
<comparison_predicate> ::= <expression> <comp_op>
<expression>
| <expression> <comp_op> <subquery>
| <expression_list> <equal_or_not> (<expression_list>)
| <expression_list> <equal_or_not>
<subquery>
expression, expression_list, subquery
The following
operators are available for comparing two values:
<, >, <>, !=, =, <=, >= (comp_op)
Value lists can only be compared with the = and <> operators (equal_or_not).
The subquery ( subquery) must supply a result table (see result table name) that contains the same number of columns as the number of values on the left of the operator. The result table may contain no more than one row.
The list of values specified to the right of the equal_or_notoperator ( expression_list) must contain the same number of values as specified in the value list in front of the equal_or_notoperator.
The JOIN predicate is a special case.
Let x be the result of the first expression and y the result of the second expression or of the subquery.
· The values x and y must be comparable with one another.
· Numbers are compared to one another according to their algebraic values.
·
Character strings are compared character by
character.
Any blanks (code attribute
ASCII, EBCDIC, UNICODE) or binary zeros (code attribute BYTE) at the end of
one or both of the character strings are removed.
If the character strings have the different code attributes ASCII and EBCDIC,
one of the two strings is converted implicitly so that they both have the same
code attribute.
If the character strings have the different code attributes ASCII or EBCDIC
and UNICODE, the character string with the code attribute ASCII or EBCDIC is
implicitly converted into a character string with the code attribute
UNICODE.
Two character strings are identical if they have the same characters in all
positions.
The relationship between two character strings that are not identical is
defined by the first character that differs in a comparison from left to
right. This comparison is performed in accordance with the code attribute
selected for this column (ASCII, EBCDIC, UNICODE, or BYTE).
· If x or y are NULL values, or if the result of the subquery is empty, (x <comp_op> y) is not defined.
If a value list (expression_list) is specified on the left of the comparison operator equal_or_not, x is the value list that comprises the results of the values x1, x2, ..., xn in this list. y is the result of the subquery or the result of the second value list. A value list y consists of the results of the values y1, y2, ..., yn.
· A value xm must be comparable with the associated value ym.
· x=y is true if for xm=ym for all m=1, ..., n.
· x<>y is true if at least xm<>ym for at least one m.
· (x <equal_or_not> y) is undefined (not known) if there is no m for which (xm <equal_or_not> ym) is false and if there is at least one m for which (xm <equal_or_not> ym) is undefined.
· If one xm or one ym is a NULL value, or if the result of the subquery is empty, (x <equal_or_not> y) is undefined.
Example table: customer
Which customers are female?
SELECT title, firstname, name FROM customer
WHERE title = 'Mrs'
TITLE |
FIRSTNAME |
NAME |
Mrs |
Jenny |
Porter |
Mrs |
Sally |
Peters |
Mrs |
Susan |
Brown |
Mrs |
Rose |
Brown |