sql: not in和联接(left join)查询的比较

 sql: not in和联接(left join)查询的比较

 

not in:

select dn,ds from (select dn,ds
from test where deleted=0
and upper(dt)='LOAN') as a where dn
not in(select ld from test2 where deleted=0)


联接(left join):

select c.dn,c.ds from
(select a.dn,a.ds,b.ld
from test as a left join test2 as b
on a.dn=b.ld
where a.deleted=0 and upper(a.dt)='LOAN'
) as c where c.ld is null

 

我觉得联接(left join) 查询效率更高速度可能更快一些
如果记录数很多可以在分别在dn,ld字段所在表加索引。

你可能感兴趣的:(Sql)