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

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

PHPz
PHPzforward
2023-08-31 12:29:02600browse

在 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)

Here, the

  • expression is the value to be searched in the set of N values ​​in the IN list. li>
  • 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)

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!

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