Home >Database >Mysql Tutorial >What is the usage of not in in mysql

What is the usage of not in in mysql

WBOY
WBOYOriginal
2021-12-27 11:51:2425814browse

In mysql, "not in" is used to determine whether the value of an expression does not exist in the given list. The syntax is "expr NOT IN (value1, value2,...)"; if the expression If the value of the formula does not exist in the specified list, the return result is 1, otherwise the return result is 0.

What is the usage of not in in mysql

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

What is the usage of not in in mysql

NOT IN is used to determine whether the value of the expression does not exist in the given list ; If not, the return value is 1, otherwise the return value is 0.

The syntax format is as follows:

expr NOT IN ( value1, value2, value3 ... valueN )

expr represents the expression to be judged, value1, value2, value3... valueN represents the value in the list. MySQL will compare the value of expr with the values ​​in the list one by one.

Examples are as follows:

mysql> SELECT 2 NOT IN (1,3,5,'thks'),'thks' NOT IN (1,3,5, 'thks');
+-------------------------+-------------------------------+
| 2 NOT IN (1,3,5,'thks') | 'thks' NOT IN (1,3,5, 'thks') |
+-------------------------+-------------------------------+
|                       1 |                             0 |
+-------------------------+-------------------------------+
1 row in set, 2 warnings (0.00 sec)

When there is a null value NULL on both sides of the NOT IN operator, if a match is not found, the return value is NULL; if found If there is a match, the return value is 0.

Examples are as follows:

mysql>  SELECT NULL NOT IN (1,3,5,'thks'),10 NOT IN (1,0,NULL,'thks');
+----------------------------+-----------------------------+
| NULL NOT IN (1,3,5,'thks') | 10 NOT IN (1,0,NULL,'thks') |
+----------------------------+-----------------------------+
|                       NULL |                        NULL |
+----------------------------+-----------------------------+
1 row in set, 1 warning (0.00 sec)
mysql>  SELECT NULL NOT IN (1,3,5,'thks'),10 NOT IN (1,10,NULL,'thks');
+----------------------------+------------------------------+
| NULL NOT IN (1,3,5,'thks') | 10 NOT IN (1,10,NULL,'thks') |
+----------------------------+------------------------------+
|                       NULL |                            0 |
+----------------------------+------------------------------+
1 row in set (0.00 sec)

Recommended learning: mysql video tutorial

The above is the detailed content of What is the usage of not in in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn