mysql any和all的用法

 
1.ANY关键字
假设any内部的查询语句返回的结果个数是三个,如:result1,result2,result3,那么,
select ...from ... where a > any(...);
->
select ...from ... where a > result1 or a > result2 or a > result3;
 
即a大于子查询中的任意一个,等同于a大于子查询的最小值即可。

2.ALL关键字
ALL关键字与any关键字类似,只不过上面的or改成and。即:
select ...from ... where a > all(...);
->
select ...from ... where a > result1 and a > result2 and a > result3;
 
即a大于子查询中的每一个,等同于a大于子查询的最大值。

3.SOME关键字
some关键字和any关键字是一样的功能。所以:
select ...from ... where a > some(...);
->
select ...from ... where a > result1 or a > result2 or a > result3;
 
posted @ 2019-06-28 10:27  板栗+  阅读(11377)  评论(4编辑  收藏  举报