|
The SQL BETWEEN operator can be used in the WHERE clause to select a range of data records between the two specified values. For example we can retrieve the result between a certain date or a numeric values.
SYNTAX:
SELECT "column_name" FROM "table_name" WHERE "column_name" BETWEEN 'value1' AND 'value2' Table: Student
| StudentID |
LastName |
FirstName |
DOB |
CourseFees |
CourseName |
| 1 |
John |
Astone |
07/15/1976 |
1000.00 |
Accountant |
| 2 |
Bob |
Eastwood |
02/13/1935 |
1500.00 |
Economic |
| 3 |
Jane |
Hollywood |
03/23/1939 |
2000.00 |
IT |
| 4 |
Bob |
Eastwood |
03/19/1980 |
3000.00 |
Economic |
EXAMPLE #1
In this example we will select all the student records who pay their course fees between 1000.00 and 2000.00.
SELECT *
FROM Student
WHERE CourseFees BETWEEN 1000 AND 2000
RESULT:
| StudentID |
LastName |
FirstName |
DOB |
CourseFees |
CourseName |
| 1 |
John |
Astone |
07/15/1976 |
1000.00 |
Accountant |
| 2 |
Bob |
Eastwood |
02/13/1935 |
1500.00 |
Economic |
| 3 |
Jane |
Hollywood |
03/23/1939 |
2000.00 |
IT |
EXAMPLE #2
In this example we will select all of the student records with their date of birth between 01/01/1970 and 01/01/1985.
SELECT *
FROM Student
WHERE DOB BETWEEN '01/01/1970' AND '01/01/1985'
RESULT:
| StudentID |
LastName |
FirstName |
DOB |
CourseFees |
CourseName |
| 1 |
John |
Astone |
07/15/1976 |
1000.00 |
Accountant |
| 4 |
Bob |
Eastwood |
02/13/1980 |
3000.00 |
Economic |
|