dongtaotao19830418 2014-12-12 11:28
浏览 232
已采纳

mysql where子句使用'IN“或多个'OR'

assuming query multiple conditions,

select AA.*,BB.* from AA left join BB on AA.key=BB.key 
where AA.key='red' or AA.key='green' or AA.key='blue' or AA.key='pink'

compare to

select AA.*,BB.* from AA left join BB on AA.key=BB.key 
where AA.key IN ['red','green',blue',pink']

In MYSQL, is any of the 2 options above faster than the other? I know using 'IN" is more pretty, but is it different in speed? (The tables have index on 'key')

I saw this post, but there is not reference about speed.

  • 写回答

3条回答 默认 最新

  • dongxi2163 2014-12-12 11:44
    关注

    RJS IN clause is more faster then Multiple OR statement in SQL.

    for example if you have 3 to 5 thousand record then IN query will be 5(approx) time faster as compared to the multiple OR statement.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试