In MySQL, how IN() comparison function works?



Basically, IN() comparison function checks whether a value is within a set of values or not. If the value is within a set of values then it returns 1 otherwise 0. Its syntax can be as follows;

Expression IN (val1, val2,…,valN)

Here,

  • The expression is the value that is to be searched within the set of N values within IN list.
  • Val1, val2,…, valN is the set of N values, forms the IN list, from which the search happens.

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)
Updated on: 2020-06-22T06:42:32+05:30

161 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements