Things to note when using NOT IN in MySql

In MySql, NOT IN is used to query data that is not in a certain value set.
When using NOT IN, you need to pay attention to the NULL value judgment. If the field value queried from the database is NULL, NOT IN will not work, such as:

SELECT name, age FROM USER WHERE age NOT IN(12,13)

The above SQL statement is used to query all users whose age is not equal to 12 or 13 in the user table. If a user does not add age information, and the field in the database is NULL, then this data cannot be found. If you want to To find out the data whose age is NULL, you can solve it by checking for null:

SELECT name, age FROM USER WHERE IFNULL(age, '') NOT IN(12,13)

Supongo que te gusta

Origin blog.csdn.net/jl15988/article/details/120505575
Recomendado
Clasificación