http://www.w3schools.com
The BETWEEN operator is used to select values within a range.
The SQL BETWEEN Operator
The BETWEEN operator selects values within a range. The values can be numbers, text, or dates.
SQL BETWEEN Syntax
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
BETWEEN Operator Example
The following SQL statement selects all products with a price BETWEEN 10 and 20:
NOT BETWEEN Operator Example
To display the products outside the range of the previous example, use NOT BETWEEN:
BETWEEN Operator with IN Example
The following SQL statement selects all products with a price BETWEEN 10 and 20, but products with a CategoryID of 1,2, or 3 should not be displayed:
Example
WHERE (Price BETWEEN 10 AND 20)
AND NOT CategoryID IN (1,2,3);
Try it yourself »
BETWEEN Operator with Text Value Example
The following SQL statement selects all products with a ProductName beginning with any of the letter BETWEEN 'C' and 'M':
NOT BETWEEN Operator with Text Value Example
The following SQL statement selects all products with a ProductName beginning with any of the letter NOT BETWEEN 'C' and 'M':
BETWEEN Operator with Date Value Example
The following SQL statement selects all orders with an OrderDate BETWEEN '04-July-1996' and '09-July-1996':
Notice that the BETWEEN operator can produce different result in different databases! Therefore: Check how your database treats the BETWEEN operator! |
'SQL' 카테고리의 다른 글
Joins (0) | 2015.06.08 |
---|---|
Aliases (0) | 2015.06.08 |
IN Operator (0) | 2015.06.07 |
Wildcards (0) | 2015.06.07 |
LIKE Operator (0) | 2015.06.07 |