2000字范文,分享全网优秀范文,学习好帮手!
2000字范文 > sql中用于子查询的几个关键词 any(some是 any的别名) all in exists

sql中用于子查询的几个关键词 any(some是 any的别名) all in exists

时间:2022-06-04 02:36:11

相关推荐

sql中用于子查询的几个关键词 any(some是 any的别名) all in exists

sql中几个子查询关键词any,all,exists,in

in,exists

in表示值是否存在子查询结果集中

select * from A where name in(select name from B)

exists是表示子查询是否返回结果,而不管返回的具体内容。

select *from A where exists( select 1 from B where name='liu');

in是“=any的简写”;

not in是“<>all”的简写

any是表示子查询结果中任意一个,all表示子查询结果中的所有。

>any表示只要大于子查询结果中的任一个,表达式就成立,=any表示等于子查询中的任一个,相当于in.

>all表示要大于子查询结果中的所有,才会返回true, not in 相当于“<>all”.

当ALL、ANY或SOME操作符与"="比较操作符配合使用时,子查询可以是一个数据表子查询。此时,你需要使用一个数据行构造器来提供与子查询所返回的数据行进行比较的比较值。

eg:select *from A where (name,num)=any(select name1,num1 from B where name='john');

in在子查询不返回数据的时候,为false,子查询结果中有null的时候,null不会用于比较。

any 同样在子查询不返回数据的时候,为false,子查询结果中有null的时候,null不会用于比较。

all在子查询不返回数据的时候,为true,子查询结果中有null的时候,不会返回数据。

not in 或not exists来代替.

not in 不等于<> any,相当于<>all,

<>any是只要不等于其中的任意一个,就成立

相关链接

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。