expr IN ( value1, value2, value3 ... valueN )
expr NOT IN ( value1, value2, value3 ... valueN )
mysql> SELECT 2 IN (1,3,5,'thks'),'thks' IN (1,3,5, 'thks'); +---------------------+---------------------------+ | 2 IN (1,3,5,'thks') | 'thks' IN (1,3,5, 'thks') | +---------------------+---------------------------+ | 0 | 1 | +---------------------+---------------------------+ 1 row in set, 2 warnings (0.00 sec) mysql> SELECT 2 NOT IN (1,3,5,'thks'),'thks' NOT IN (1,3,5, 'thks'); +-------------------------+-------------------------------+ | 2 NOT IN (1,3,5,'thks') | 'thks' NOT IN (1,3,5, 'thks') | +-------------------------+-------------------------------+ | 1 | 0 | +-------------------------+-------------------------------+ 1 row in set, 2 warnings (0.00 sec)由结果可以看到,IN 和 NOT IN 的返回值正好相反。
mysql> SELECT NULL IN (1,3,5,'thks'),10 IN (1,3,NULL,'thks'); +------------------------+-------------------------+ | NULL IN (1,3,5,'thks') | 10 IN (1,3,NULL,'thks') | +------------------------+-------------------------+ | NULL | NULL | +------------------------+-------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> SELECT NULL IN (1,3,5,'thks'),10 IN (1,10,NULL,'thks'); +------------------------+--------------------------+ | NULL IN (1,3,5,'thks') | 10 IN (1,10,NULL,'thks') | +------------------------+--------------------------+ | NULL | 1 | +------------------------+--------------------------+ 1 row in set (0.00 sec)
mysql> SELECT NULL NOT IN (1,3,5,'thks'),10 NOT IN (1,0,NULL,'thks'); +----------------------------+-----------------------------+ | NULL NOT IN (1,3,5,'thks') | 10 NOT IN (1,0,NULL,'thks') | +----------------------------+-----------------------------+ | NULL | NULL | +----------------------------+-----------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> SELECT NULL NOT IN (1,3,5,'thks'),10 NOT IN (1,10,NULL,'thks'); +----------------------------+------------------------------+ | NULL NOT IN (1,3,5,'thks') | 10 NOT IN (1,10,NULL,'thks') | +----------------------------+------------------------------+ | NULL | 0 | +----------------------------+------------------------------+ 1 row in set (0.00 sec)
本文链接:http://task.lmcjl.com/news/12485.html