Please visit our sponsors !
SQL Between...And
BETWEEN ... AND
The BETWEEN ... AND operator selects an inclusive range of data between two
values. These values can be numbers, text, or dates.
SELECT column_name FROM table_name
WHERE column_name
BETWEEN value1 AND value2
|
Original Table (used in the examples)
| LastName |
FirstName |
Address |
City |
| Hansen |
Ola |
Timoteivn 10 |
Sandnes |
| Nordmann |
Anna |
Neset 18 |
Sandnes |
| Pettersen |
Kari |
Storgt 20 |
Stavanger |
| Svendson |
Tove |
Borgvn 23 |
Sandnes |
Example 1
To display the persons alphabetically between (and including) "Hansen" and
"Pettersen", use the following SQL:
SELECT * FROM Persons WHERE LastName
BETWEEN 'Hansen' AND 'Pettersen'
|
Result:
| LastName |
FirstName |
Address |
City |
| Hansen |
Ola |
Timoteivn 10 |
Sandnes |
| Nordmann |
Anna |
Neset 18 |
Sandnes |
| Pettersen |
Kari |
Storgt 20 |
Stavanger |
Example 2
To display the persons outside the range used in the previous example, use the NOT operator:
SELECT * FROM Persons WHERE LastName
NOT BETWEEN 'Hansen' AND 'Pettersen'
|
Result:
| LastName |
FirstName |
Address |
City |
| Svendson |
Tove |
Borgvn 23 |
Sandnes |
Jump to: Top of Page
or HOME or
Printer friendly page
Search W3Schools:
What Others Say About Us
Does the world know about us? Check out these places:
Dogpile
Alta Vista
MSN
Google
Excite
Lycos
Yahoo
Ask Jeeves
We Help You For Free. You Can Help Us!
W3Schools is for training only. We do not warrant its correctness or its fitness for use.
The risk of using it remains entirely with the user. While using this site, you agree to have read and accepted our
terms of use and
privacy policy.
Copyright 1999-2002 by Refsnes Data. All Rights Reserved
|