The BETWEEN operator can evaluate whether or not data values fall within the range of values indicated in the predicate.
Each occurrence of the expression
x
is evaluated to determine if it sorts between and including the range values indicated by
y
and
z
(the range values in the BETWEEN clause are also part of the result set). The three variables above can consist of any combination of value expressions, although
x
is typically a column name.
Note that the value of
y
should be less than that of
z
. Otherwise, in the case of literals, an error will be returned; in the case of numeric expressions, the predicate will always return FALSE.
The following query selects all Part table records with
weight
column values between 15 and 18:
SELECT pno, pname
FROM part
WHERE weight BETWEEN 15 AND 18;
The following table displays the records retrieved: