當前位置:秀美範 >

生活 >經驗 >

exists用法 exists用法講解

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子句不在乎返回什麼,而是在乎是不是有結果集返回。

標籤: exists 講解
  • 文章版權屬於文章作者所有,轉載請註明 https://xiumeifan.com/shenghuo/jingyan/zgrd3v.html