假设原来的句子是
select * from t1 where t1.f1 in (select t2.f2 from t2 where t2.f2=xxx)
和你的很类似
你用子查询 很慢
我们现在修改为:
select t1.* from t1 ,t2 where t1.f1 = t2.f2 and t2.f2=xxxx
这里使用了关联查询代替了子查询大大提高效率。
其次你可以考虑在表t1.f1上加索引,提高查询速度。
这样试下:
把id放到一张表中,
where id in(select id from 表)
尝试在 in 的这个字段上建索引
select * from t1
join t2 on t1.f1=t2.f2
where t2.f2=xxx