exists用法 exists用法講解


1、EXISTS在SQL中的作用是:檢驗查詢是否返回數據。select a.* from tb a where exists(select 1 from tb where name =a.name)返回真假,當 where 后面的條件成立,則列出數據,否則為空。

2、exists強調的是是否返回結果集,不要求知道返回什么。比如:select name from student where sex = 'm' and mark exists(select 1 from grade where ...)

3、只要exists引導的子句有結果集返回,那么exists這個條件就算成立了,大家注意返回的字段始終為1,如果改成“select 2 from grade where ...”,那么返回的字段就是2,這個數字沒有意義。所以exists子句不在乎返回什么,而是在乎是不是有結果集返回。

 

 

轉 https://m.yxlady.com/jingyan/247317.shtml


免責聲明!

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



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