mysql in语句查询

select * from help_relation h where h.help_topic_id = 232;
select * from help_relation h where h.help_topic_id in (232);
这两种方式有区别吗,哪一种更好一些

没啥区别其实,都可以正常走索引,非要说的话第一条高点但有限,但如果是id=232 or id=233 or.... 和 id in(232,233...)

这种特别多时,并且id字段没有索引,那么=加上or的效率会远远低于in的效率,如果有索引那基本没差
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-13
第一条效率高 也就是 =
in一般用于一个范围内的查找,比如查找id为212,231,232:
select * from help_relation h where h.help_topic_id in (212,231,232);
第2个回答  2013-09-13
in的执行效率没有 = 的快
第3个回答  2013-09-13
第一条语句效率高些