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

Detailed explanation of IN and NOT IN usage in MySQL

autoload
Release: 2021-04-15 14:10:29
Original
11809 people have browsed it

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 )
Copy after login

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 )
Copy after login

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)
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template