Comparison Predicates
A comparison predicate consists of two expressions connected with a comparison operator.There are six traditional comparison operators:
=, >, <, >=, <=, <>
For the complete list of comparison operators with their variant forms, see Comparison Operators.
If one of the sides (left or right) of a comparison predicate has NULL
in it, the value of the predicate will be UNKNOWN
.
-
Retrieve information about computers with the CPU frequency not less than 500 MHz and the price lower than $800:
SELECT * FROM Pc WHERE speed >= 500 AND price < 800;
-
Retrieve information about all dot matrix printers that cost less than $300:
SELECT * FROM Printer WHERE ptrtype = 'matrix' AND price < 300;
-
The following query will return no data, even if there are printers with no type specified for them, because a predicate that compares
NULL
withNULL
returnsNULL
:SELECT * FROM Printer WHERE ptrtype = NULL AND price < 300;
On the other hand,
ptrtype
can be tested forNULL
and return a result: it is just that it is not a comparison test:SELECT * FROM Printer WHERE ptrtype IS NULL AND price < 300;
Note
|
Note about String Comparison
When |