首页
/
每日頭條
/
科技
/
exists用法
exists用法
更新时间:2025-05-14 16:21:25

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

Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2025 - www.tftnews.com All Rights Reserved