Oracle中 in、exists、not in,not 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