Mysql BETWEEN
From w3cyberlearnings
Contents |
MySQL BETWEEN.. AND...
This function checks the expression in the range of value.
Syntax BETWEEN ... AND ...
- Expre is greater than or equal to min and Expre is less than or equal to max.
Expre BETWEEN min AND max
Note
expr Between min AND max = (min <= expr AND expr <= max)
Example 1
mysql> SELECT 1 BETWEEN 0 AND 3; +-------------------+ | 1 BETWEEN 0 AND 3 | +-------------------+ | 1 | +-------------------+ 1 row in set (0.00 sec)
Example 2
mysql> SELECT 'c' BETWEEN 'b' AND 'z'; +-------------------------+ | 'c' BETWEEN 'b' AND 'z' | +-------------------------+ | 1 | +-------------------------+ 1 row in set (0.00 sec)
Example 3
mysql> SELECT * FROM student; +------------+------+------+ | student_id | name | age | +------------+------+------+ | 1 | John | 28 | | 2 | Bob | 30 | | 3 | Kat | 28 | | 4 | Pher | 24 | | 5 | Jim | 21 | +------------+------+------+ 5 rows in set (0.00 sec) mysql> SELECT * FROM student WHERE -> age BETWEEN 28 AND 30; +------------+------+------+ | student_id | name | age | +------------+------+------+ | 1 | John | 28 | | 2 | Bob | 30 | | 3 | Kat | 28 | +------------+------+------+ 3 rows in set (0.00 sec)