6.2.2 Checking whether a value is in a certain range
Use the BETWEEN predicate to check whether a value is in a certain range. The following are examples of specifying
the BETWEEN predicate:
Example 1:
In this example, rows for which STOCKQTY is greater than or equal to 50 but less than or equal to 100
are fetched from the STOCK table.
The result of the BETWEEN predicate is true if the following conditions, based on the three value expressions, are
satisfied:
The result is false if value expression [1] is less than value expression [2] or greater than value expression [3].
The result is undefined if value expression [1] is a null value or is greater than or equal to value expression [2], and
value expression [3] is a null value. The result is also undefined if value expression [1] is less than or equal to value
expression [3] and value expression [2] is a null value.
Example 2:
In this example, rows for which STOCKQTY is greater than or equal to 10 but less than or equal to 50,
or greater than or equal to 200 but less than or equal to 300 are fetched.
SELECT ... FROM STOCKS. STOCK
WHERE STOCKQTY BETWEEN 10 AND 50
OR STOCKQTY BETWEEN 200 AND 300
Example 3:
In this example, rows for which PRICE x ORDERQTY is less than 1,000,000 or greater than 2,000,000
are fetched from the ORDER table.
94