您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

mysql中not in的用法是什么

2025/8/25 15:23:09发布26次查看
在mysql中,“not in”用于判断表达式的值是否不存在于给出的列表中,语法为“expr not in(value1,value2,...)”;如果表达式的值不存在指定列表中,返回结果是1,否则返回结果是0。
本教程操作环境: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的用法是什么的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product