Home  >  Article  >  Database  >  Detailed explanation of IN and NOT IN usage in MySQL

Detailed explanation of IN and NOT IN usage in MySQL

autoload
autoloadOriginal
2021-03-26 16:27:2611718browse

Detailed explanation of IN and NOT IN usage in MySQL

In daily operations on the MySQL database, we often use NOT IN and IN. This article mainly talks about, MySQL Medium IN and NOT IN usage.

1. The syntax format of IN and NOT IN

The IN operator in MySQL is used to determine whether the value of the expression is in the given in the list; if so, the return value is 1, otherwise the return value is 0.

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

The function of NOT IN is exactly the opposite of IN. 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.

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.

2. The difference between the two:

SELECT DISTINCT from_id  FROM  table_cod
WHERE cod.from_id NOT IN (37, 56, 57)

will exclude null when not in.

If there is null when querying in, it will not affect the result.

Recommendation: "mysql tutorial"

The above is the detailed content of Detailed explanation of IN and NOT IN usage 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