Oracle中in和exists的選擇

2021-07-10 21:17:16 字數 361 閱讀 7435

在oracle 11g大行其道的今天,還有很多人受早期版本的影響,記住一些既定的規則,

1.子查詢結果集小,用in

2.外表小,子查詢表大,用exists

簡單說明:

a表的資料小,b表資料大時用exists。a為外表(也為主表)

select * from a

where exists(

select 1 from b where a.employee_id=b.employee_id);

b表資料量小(子表)時,用in。

select * from a

where a.employee_id in (select b.employee_id from b);

ORACLE 中exist和in的區別

博文 oracle中的exists 和not exists 用法 博文 in與exists語句的效率問題 一 exists sql 返回結果集為真 notexists sql 不返回結果集為真 如下 表a id name 1a1 2a2 3a3 表b id aid name 11b1 22b2 32...

oracle常識(一) in和exist的區別

in 與 exist 的語法比較 select from 資料表 t where t.x in 括號內可以是符合t.x欄位型別的值集合,如 1 2 3 但如果t.x是number型別的時候,似乎這樣的寫法會出問題 也可以是通過另外的select語句查詢出來的值集合,如 select y from 資...

sql中in和exist語句的區別?

in和exists in 是把外表和內錶作hash 連線,而exists是對外表作loop迴圈,每次loop迴圈再對內表進行查詢。如果兩個表中乙個較小,乙個是大表,則子查詢表大的用exists,子查詢錶小的用in 例如 表a 小表 表b 大表 1 select from a where cc in ...