Jump to: navigation, search

Mysql NOT IN

From w3cyberlearnings

Contents

MySQL NOT IN Function

This function returns 1 when the expre is NOT in a list. It is the same as NO(IN(val1, val2..)).

Syntax NOT IN

Expr checks against value in a list.

Expr NOT IN(val1, val2,val3..);

Example 1

mysql> SELECT 320 NOT IN(30,20,40);
+----------------------+
| 320 NOT IN(30,20,40) |
+----------------------+
|                    1 |
+----------------------+
1 row in set (0.00 sec)

mysql> SELECT 320 NOT IN(30,320,40);
+-----------------------+
| 320 NOT IN(30,320,40) |
+-----------------------+
|                     0 |
+-----------------------+
1 row in set (0.00 sec)

Example 2

mysql> SELECT * FROM item;
+---------+----------+-------+
| item_id | item     | price |
+---------+----------+-------+
|       1 | CD       |     5 |
|       2 | PHONE    |    45 |
|       3 | Laptop   |   880 |
|       4 | Iphone   |     0 |
|       5 | eyephone |    10 |
|       6 | ebook    |     0 |
+---------+----------+-------+
6 rows in set (0.00 sec)

mysql> SELECT * FROM item WHERE item NOT IN('java2','php5','CD','PHONE');
+---------+----------+-------+
| item_id | item     | price |
+---------+----------+-------+
|       3 | Laptop   |   880 |
|       4 | Iphone   |     0 |
|       5 | eyephone |    10 |
|       6 | ebook    |     0 |
+---------+----------+-------+
4 rows in set (0.00 sec)

Related Links



Navigation
Web
SQL
MISC
References