基本上,IN()比较函数检查一个值是否在一组值内。如果该值在一组值之内,则返回1,否则返回0。其语法可以如下:
Expression IN (val1, val2,…,valN)
这里,
该表达式是要在IN列表的N个值集中搜索的值。
Val1,val2,…,valN是N个值的集合,形成IN列表,从中进行搜索。
Select 100 IN (50,100,200,400,2000); +------------------------------+ | 100 IN (50,100,200,400,2000) | +------------------------------+ | 1 | +------------------------------+ 1 row in set (0.00 sec) Select 1000 IN (50,100,200,400,2000); +-------------------------------+ | 1000 IN (50,100,200,400,2000) | +-------------------------------+ | 0 | +-------------------------------+ 1 row in set (0.00 sec) Select 'ABC' IN ('ABCD','ABCDE','ABC'); +---------------------------------+ | 'ABC' IN ('ABCD','ABCDE','ABC') | +---------------------------------+ | 1 | +---------------------------------+ 1 row in set (0.01 sec) Select 'ABC' IN ('ABCD','ABCDE','ABCDEF'); +------------------------------------+ | 'ABC' IN ('ABCD','ABCDE','ABCDEF') | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set (0.00 sec)