有两个表 表A,表B 两个表通过ID连接 已知道表A中有记录 3W条左右 ,表B有记录300W左右。
现语句如下:select ID from 表A a where ( NO > '苏B' or NO < '苏A' ) and State = 0 and not exists( select 1 from 表B b where a.ID = b.ID );但是这样查询很慢(经过测试主要是not exists 条件比较慢),请问是否有其他语句能够提高速度并符合上述查询条件?
现语句如下:select ID from 表A a where ( NO > '苏B' or NO < '苏A' ) and State = 0 and not exists( select 1 from 表B b where a.ID = b.ID );但是这样查询很慢(经过测试主要是not exists 条件比较慢),请问是否有其他语句能够提高速度并符合上述查询条件?
where ( NO > '苏B' or NO < '苏A' ) and State = 0 and
a.id=b.id(+)
and b.id is null
A表左联接B表,取关联不上的数据.
也就相当于取了在A表而不在B表的数据.
select ID from 表A a left join 表B b on a.ID = b.ID and b.ID is null
where ( NO > '苏B' or NO < '苏A' ) and State = 0 10g对于
我这也写 觉得更加规范些
select ID from 表A a left join 表B b on a.ID = b.ID where ( NO > '苏B' or NO < '苏A' ) and State = 0 and b.ID is null