select distinct * from table1
where table1.字段1 not in(select table2.字段1 from table2)执行上面的查询奇慢table1 大约有200万条数据
table2 大约有2000万条数据
table1和table2都没有设置索引请教高手如何能提高查询的速度?
where table1.字段1 not in(select table2.字段1 from table2)执行上面的查询奇慢table1 大约有200万条数据
table2 大约有2000万条数据
table1和table2都没有设置索引请教高手如何能提高查询的速度?
sql改成
select * from table1
where not exists (select 1 from table2 where table2.字段1 = table1.table1);希望有所幫助。
2,将语句修改为
select distinct * from table1
where not exists(select 1 from table2 where table1.字段1 = table2.字段1)
talbe1的字段1是没有重复值的
table2的字段1有重复值另外到底需不需要两个表都建立索引
select distinct * from table1
where not exists(select 1 from table2 where table1.字段1 = table2.字段1)2.建议不要用‘*’代替所有列名。
命令:create index uindx_1 on table2(字段1);
where table1.字段1=table2.字段1(+) and table2.字段1 is null这样查询可能快一点
create index uindx_1 on table1(字段1);
create index uindx_2 on table2(字段1);
select distinct * from table1 where table1.字段1 not exists (select table1.字段1 from table2,table1 where table1.字段1=table2.字段1);
create index uindx_1 on table1(字段1);
create index uindx_2 on table2(字段1);
select distinct * from table1 where not exists (select table1.字段1 from table2,table1 where table1.字段1=table2.字段1);
尝试一下这样select table1.字段1
from table1
where table1.字段1 = table2.字段1(+)
and table2.字段1 is null
group by table1.字段1
这个也可以尝试一下
方法二: select table1.字段1
from table1
group by table1.字段1 except
select table2.字段1 from table2 group by table2.字段1
希望对你有帮助,一般来说尽量不要用DISTINCT , 实在是业务需要的话, 找点别的方法替代.
最好的办法是说服客户,不要这样做哈...............
where table1.字段1 not in(select table2.字段1 from table2)1.把这个语句修改为join来处理,
2.建立索引