要对比两张表TA和TB:
select *
from TA a
where not exists
(select v_key from TB b where a.v_key = b.v_key);
select *
from TA, (select v_key from TB) c
where TA.v_key = c.v_key(+)
and c.v_key is null;
如果表TA和TB都有大量数据的话,哪个效率会比较高一点?
要对比两张表TA和TB:
select *
from TA a
where not exists
(select v_key from TB b where a.v_key = b.v_key);
select *
from TA, (select v_key from TB) c
where TA.v_key = c.v_key(+)
and c.v_key is null;
如果表TA和TB都有大量数据的话,哪个效率会比较高一点?
第一个效率高。
首先,使用 EXIST,Oracle 系统会首先检查主查询,然后运行子查询直到它找到第一个匹配项,这就节省了时间。
其次,任何 SQL语句,只要在 where子句中使用了 is null或 is not null,那么 Oracle优化器就不允。