ASA SQL User's Guide
Queries: Selecting Data from a Table
The WHERE clause: specifying rows
The BETWEEN keyword specifies an inclusive range, in which the lower value and the upper value are searched for as well as the values they bracket.
To list all the products with prices between $10 and $15, inclusive
Type the following query:
SELECT name, unit_price FROM product WHERE unit_price BETWEEN 10 AND 15
name | unit_price |
---|---|
Tee Shirt | 14 |
Tee Shirt | 14 |
Baseball Cap | 10 |
Shorts | 15 |
You can use NOT BETWEEN to find all the rows that are not inside the range.
To list all the products cheaper than $10 or more expensive than $15
Execute the following query:
SELECT name, unit_price FROM product WHERE unit_price NOT BETWEEN 10 AND 15
name | unit_price |
---|---|
Tee Shirt | 9 |
Baseball Cap | 9 |
Visor | 7 |
Visor | 7 |
... | ... |