Home > Database > Mysql Tutorial > How does the IN() comparison function work in MySQL?

How does the IN() comparison function work in MySQL?

PHPz
Release: 2023-08-31 12:29:02
forward
619 people have browsed it

在 MySQL 中,IN() 比较函数如何工作?

Basically, the IN() comparison function checks whether a value is within a set of values. Returns 1 if the value is within a set of values, 0 otherwise. The syntax is as follows;

Expression IN (val1, val2,…,valN)
Copy after login

Here, the

  • expression is the value to be searched in the set of N values ​​in the IN list.
  • Val1, val2,…, valN is a set of N values ​​forming an IN list from which to search.

Example

mysql> Select 100 IN (50,100,200,400,2000);
+------------------------------+
| 100 IN (50,100,200,400,2000) |
+------------------------------+
|                            1 |
+------------------------------+
1 row in set (0.00 sec)

mysql> Select 1000 IN (50,100,200,400,2000);
+-------------------------------+
| 1000 IN (50,100,200,400,2000) |
+-------------------------------+
|                             0 |
+-------------------------------+
1 row in set (0.00 sec)

mysql> Select 'ABC' IN ('ABCD','ABCDE','ABC');
+---------------------------------+
| 'ABC' IN ('ABCD','ABCDE','ABC') |
+---------------------------------+
|                               1 |
+---------------------------------+
1 row in set (0.01 sec)

mysql> Select 'ABC' IN ('ABCD','ABCDE','ABCDEF');
+------------------------------------+
| 'ABC' IN ('ABCD','ABCDE','ABCDEF') |
+------------------------------------+
|                                  0 |
+------------------------------------+
1 row in set (0.00 sec)
Copy after login

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

source:tutorialspoint.com
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