To select the values within a selected range BETWEEN operator is used.
The values can be numbers, text, or dates. And it includes start and end values too.
Syntax:
SELECT * FROM table_name
WHERE column_name BETWEEN value1 AND value2;
DEMO STUDENTS TABLE
Roll_No | Name | Marks |
1 | Dev | 35 |
2 | Ayush | 45 |
3 | Ram | 55 |
4 | Pyush | 65 |
5 | Nazim | 75 |
Example: To select the students between 1 to 3 roll numbers.
SELECT * FROM students
WHERE Roll_No BETWEEN 1 AND 3;
This will fetch the values as shown below:
Roll_No | Name | Marks |
1 | Dev | 35 |
2 | Ayush | 45 |
3 | Ram | 55 |
NOT BETWEEN: It is used to select outside the selected range.