本教程操作环境:windows10系统、mysql8.0.22版本、dell g3电脑。
mysql中not in的用法是什么
not in 用来判断表达式的值是否不存在于给出的列表中;如果不是,返回值为 1,否则返回值为 0。
语法格式如下:
expr not in ( value1, value2, value3 ... valuen )
expr 表示要判断的表达式,value1, value2, value3 ... valuen 表示列表中的值。mysql 会将 expr 的值和列表中的值逐一对比。
示例如下:
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)
当 not in 运算符的两侧有一个为空值 null 时,如果找不到匹配项,则返回值为 null;如果找到了匹配项,则返回值为 0。
示例如下:
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)
推荐学习:mysql视频教程
以上就是mysql中not in的用法是什么的详细内容。
