A comparison condition is used to compare one expression with another, and the comparison result can be TRUE, FALSE, or UNKNOWN.
Note
For more information about comparison operators, see Comparison operators.
The following table describes the comparison conditions in detail.
Condition type |
Feature |
Example |
|---|---|---|
| = | equal | SELECT * FROM emp WHERE salary = 2000 ORDER BY empno; |
| != or <> | Not equal | SELECT * FROM emp WHERE salary != 2000 ORDER BY empno; |
| > < | greater than less than | SELECT * FROM emp WHERE salary > 2000 ORDER BY empno; |
| >= <= | Greater than or equal toLess than or equal to | SELECT * FROM emp WHERE salary >= 2000 ORDER BY empno; |
| <=> | NULL-safe equality (NULL-safe comparison) | SELECT * FROM emp WHERE salary <=> NULL ORDER BY empno; |
Simple comparison conditions
The syntax for a simple comparison condition is as follows:
expr {= | != | <> | < | > | <= | >= | <=>} expr
Group comparison conditions
You can use ANY, SOME, and ALL to compare an expression with the results of a subquery.
Comparison with subqueries
expr {= | != | <> | < | > | <= | >=} { ANY | SOME | ALL } ( subquery )
ANY is equivalent to SOME. Example:
obclient> SELECT * FROM emp WHERE salary = ANY (SELECT salary FROM emp WHERE deptno = 30) ORDER BY empno;
obclient> SELECT * FROM emp WHERE salary > ALL (SELECT salary FROM emp WHERE deptno = 30) ORDER BY empno;
Comparison with single-element lists
The expression = ANY (list of single elements) is rewritten as the array_contains operation during parsing, and the parentheses must contain only one expression:
-- Equivalent to array_contains semantics
SELECT * FROM emp WHERE id = ANY ((100));
Notice
= ANY (multi-element list) is not supported; use the IN condition to check for multi-valued members.
