In MySQL, the BETWEEN operator is used to select values (values can be numbers, text, or dates) from a column within a specified range.
BETWEEN Syntax
SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
We have a table "employee" as below:
employee
id first_name last_name salary
.......................................................
1 John Simp 10000
2 Chris Hely 15000
3 Max Roy 30000
4 Jenny Mill 25000
5 Jack Simpson 12000
BETWEEN Operator Example
The below statement selects all employee with a salary BETWEEN 10000 and 20000:
SELECT * FROM employee
WHERE salary BETWEEN 10000 AND 20000;
Result
id first_name last_name salary
.......................................................
1 John Simp 10000
2 Chris Hely 15000
5 Jack Simpson 12000
NOT BETWEEN Operator Example
To get the records which are not in specified range, we use NOT BETWEEN keyword as below:
SELECT * FROM employee
WHERE salary NOT BETWEEN 10000 AND 20000;
Result
id first_name last_name salary
.......................................................
3 Max Roy 30000
4 Jenny Mill 25000
Hope this will help you :)
0 Comment(s)