日期:2014-05-17  浏览次数:20735 次

sql中关于in的效率问题
SELECT * FROM a where aId In(46,47,99,121,313,321,1,62,48,49)
这条语句能不能优化

有人说join或EXISTS代替IN会提高效率

我研究了半天也没研究出来

------解决方案--------------------
但你这种情况只能用in唉,如果你的这些id是存在其他表中的可以用exists替换
------解决方案--------------------
http://www.itpub.net/thread-1070206-1-1.html
看看这篇帖子
另外,10g之后,Oracle使用CBO.
------解决方案--------------------
select * from a where a.xx in (1,2,3,4,5,6);
select * from a where exists (select 1 from b where a.xx = b.xx);