Jump to: navigation, search

Mysql NOT BETWEEN

From w3cyberlearnings

Contents

MySQL NOT Between.. AND...

This function checks the expression not in the range of value.

Syntax NOT BETWEEN ... AND ...

  • Expre is not greater than or equal to min and Expre is not less than or equal to max.
Expre NOT BETWEEN min AND max or  NOT (Expr BETWEEN min AND max)

Example 1

mysql> SELECT 70 NOT BETWEEN 60 AND 100;
+---------------------------+
| 70 NOT BETWEEN 60 AND 100 |
+---------------------------+
|                         0 |
+---------------------------+
1 row in set (0.00 sec)

mysql> SELECT 70 NOT BETWEEN 80 AND 100;
+---------------------------+
| 70 NOT BETWEEN 80 AND 100 |
+---------------------------+
|                         1 |
+---------------------------+
1 row in set (0.00 sec)

Example 2

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 NOT BETWEEN 28 AND 30;
+------------+------+------+
| student_id | name | age  |
+------------+------+------+
|          4 | Pher |   24 |
|          5 | Jim  |   21 |
+------------+------+------+
2 rows in set (0.00 sec)

Related Links



Navigation
Web
SQL
MISC
References