Home >Database >Mysql Tutorial >When does the MySQL IN() function return NULL?

When does the MySQL IN() function return NULL?

WBOY
WBOYforward
2023-09-11 16:49:061306browse

MySQL IN() 函数何时返回 NULL?

The following are two cases when the MySQL IN() function returns NULL as the result-

Case 1 - When the left-hand expression is NULL h2>

If the left-hand expression is NULL, the IN() function will return NULL. The following example will demonstrate it -

mysql> Select NULL IN (1,2,3,4,10);
+----------------------+
| NULL IN (1,2,3,4,10) |
+----------------------+
|       NULL           |
+----------------------+
1 row in set (0.00 sec)

Case 2 - When one of the expressions in the list is NULL and no match is found

IN() function If no match is found, will return NULL and one of the expressions in the list is NULL. If there is a match and one of the expressions in the list is NULL, it will return 1 as output. The following example will demonstrate it -

mysql> Select 10 IN (NULL,11,12);
+--------------------+
| 10 IN (NULL,11,12) |
+--------------------+
|      NULL          |
+--------------------+
1 row in set (0.00 sec)

mysql> Select 10 IN (NULL,11,12,10);
+-----------------------+
| 10 IN (NULL,11,12,10) |
+-----------------------+
|         1             |
+-----------------------+
1 row in set (0.00 sec)

The above is the detailed content of When does the MySQL IN() function return NULL?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete