select * from t where id=1 or id=2 or id=3 order by s desc
select * from t where id<4 order by s desc
select * from t where exists(1,2,3) order by s desc
select * from t where id<4 order by s desc
select * from t where exists(1,2,3) order by s desc
优化器把使用IN比较符的检索表达式替换为等价的使用“=”和“OR”操作符的检索表达式。
不过,用in有时也是很方便的,in是通用SQL,exists不知道是不是了!
如果id是主键
实际情况下,in和exists和or的效率是一样的。
没有必要再做任何优化。看来verycd出题的人自己对mysql也不大了解,只是道听途说
\\ - - //
( @ @ )
┏━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━┓