1. 程式人生 > >Oracle中 in、exists、not in,not exists的比較

Oracle中 in、exists、not in,not exists的比較

src inf .... blog pos str bug class exists

最基本的區別:

  • in 對主表使用索引
  • exists 對子表使用索引
  • not in 不使用索引
  • not exists 對主子表都使用索引

寫法:

  • exist的where條件是: "...... where exist (..... where a.id=b.id)"
  • in的where條件是: " ...... where id in ( select id .... where a.id=b.id)"

BUG【要特別註意】:

這是用來舉例的表

技術分享圖片

IN【正常】、NOT IN【不正常】的情況

IN【正常】

技術分享圖片

實際轉換為執行的SQL等價於

技術分享圖片

NOT IN【不正常】
技術分享圖片

實際轉換為執行的SQL等價於

技術分享圖片

修改SQL

技術分享圖片

純手打:麻煩點下推薦支持原創 ((o(^_ ^)o))

Oracle中 in、exists、not in,not exists的比較