數據庫ALL和ANY的區別


這兩個都是用於子查詢的

any 是任意一個 
all 是所有

any表示有任何一個滿足就返回true,all表示全部都滿足才返回true

比如 :

select * from student where 班級=’01’ and age > all (select age from student where 班級=’02’);
  • 1

就是說,查詢出01班中,年齡大於 02班所有人的同學 相當於

select * from student where 班級=’01’ and age > (select max(age) from student where 班級=’02’);
  • 1

select * from student where 班級=’01’ and age > any (select age from student where 班級=’02’); 
  • 1

就是說,查詢出01班中,年齡大於 02班任意一個 的 同學 相當於

select * from student where 班級=’01’ and age > (select min(age) from student where 班級=’02’);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM