|
<< Click to Display Table of Contents >> BETWEEN predicate |
![]() ![]()
|
Determines whether a value falls inside a range.
value1 [NOT] BETWEEN value2 AND value3
Use the BETWEEN comparison predicate to compare a value to a value range. If the value is greater than or equal to the low end of the range and less than or equal to the high end of the range, BETWEEN returns a TRUE value. If the value is less than the low end value or greater than the high end value, BETWEEN returns a FALSE value. For example, the expression below returns a FALSE value because 10 is not between 1 and 5.
10 BETWEEN 1 AND 5
Use NOT to return the converse of a BETWEEN comparison. For example, the expression below returns a TRUE value.
10 NOT BETWEEN 1 AND 5
BETWEEN can be used with all non-BLOB data types, but all values compared must be of the same or a compatible data type. If one value is of an incompatible data type, convert that value with the CAST function to a compatible data type. Values used in a BETWEEN comparison may be column, literal, or calculated values.
SELECT Saledate
FROM Orders
WHERE (Saledate BETWEEN "1/1/1988" AND "12/31/1988")
Hint: BETWEEN is useful when filtering to retrieve rows with contiguous values that fall within the specified range. For filtering to retrieve rows with noncontiguous values, use the IN predicate.