mysql 中
select * from u where user_name =1 or user_email =2
用or链接 如果user_name 和 user_email 建立索引 mysql是会 忽略掉两者的索引
此时 可以用 union操作来 链接 条件
select * from u where user_name =1
union
select * from u where user_email =2
本文探讨了在MySQL中使用UNION操作符优化查询性能的方法,特别是当用户名和邮箱字段分别查询时,通过UNION避免了使用OR连接导致的索引失效问题,从而提高了查询效率。
mysql 中
select * from u where user_name =1 or user_email =2
用or链接 如果user_name 和 user_email 建立索引 mysql是会 忽略掉两者的索引
此时 可以用 union操作来 链接 条件
select * from u where user_name =1
union
select * from u where user_email =2

被折叠的 条评论
为什么被折叠?