經驗

當前位置 /首頁/生活/經驗/列表

exists用法 exists用法講解

exists用法 exists用法講解

1、EXISTS在SQL中的作用是:檢驗查詢是否返回資料。select a.* from tb a where exists(select 1 from tb where 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子句不在乎返回什麼,而是在乎是不是有結果集返回。

TAG標籤:講解 exists #