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

时间:2024-06-26 14:35:14

最基本的区别:

  • 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【要特别注意】:

这是用来举例的表

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

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

IN【正常】

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

实际转换为执行的SQL等价于

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

NOT IN【不正常】
Oracle中 in、exists、not in,not exists的比较

实际转换为执行的SQL等价于

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

修改SQL

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