Home >Database >Mysql Tutorial >How does the IN() comparison function work in MySQL?
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
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!