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

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.

图片转代码服务由CSDN问答提供 功能建议

假设查询多个条件,

 选择AA。*,  BB。*从AA离开加入BB在AA.key = BB.key 
其中AA.key ='red'或AA.key ='green'或AA.key ='blue'或AA.key ='pink'\  n   
 
 

比较

 选择AA。*,BB。*从AA左侧加入BB在AA.key =  BB.key 
其中AA.key IN ['red','green',blue',pink'] 
   
 
 

在MYSQL中,是2个选项中的任何一个 上面比其他更快? 我知道使用'IN'更漂亮,但它的速度是否不同? (表中有'key'的索引)

我看到< a href =“https://stackoverflow.com/questions/17870/select-where-or”>这篇帖子,但没有关于速度的参考。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

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条)

相关推荐 更多相似问题