The BETWEEN command enables the selection of values falling within a specified range, inclusive of numbers, text, or dates.
The BETWEEN command inclusively selects values, including both the beginning and end values.
In the following SQL statement, all products with prices ranging from 10 to 20 are selected.
SELECT * FROM Products WHERE Price BETWEEN 10 AND 20; |
To showcase products beyond the range mentioned in the previous example, employ the NOT BETWEEN operator.
SELECT * FROM Products WHERE Price NOT BETWEEN 10 AND 20; |
The provided SQL statement retrieves all products with a ProductName falling within the range from ‘Carnarvon Tigers’ to ‘Mozzarella di Giovanni’.
SELECT * FROM Products WHERE ProductName BETWEEN ‘Carnarvon Tigers’ AND ‘Mozzarella di Giovanni’ ORDER BY ProductName; |