sql语句中用连接查询时慎用or

内容纲要

这是原来的语句

select a.symbol,a.expertid,a.companyname,b.email,b.phone,c.cname,m.nickname,a.expertid,m.uid from companyresearch as a
left join expertcontact as b on a.expertid=b.expertid
left join members as m on b.email = m.email or b.name=m.nickname
left join company_user as c on m.uid=c.uid
where a.symbol=’000826′ and a.expertid>0 group by m.nickname order by a.time desc limit 0,10

查询需要107秒

这是改进后的语句

select a.symbol,a.expertid,a.companyname,b.email,b.phone,c.cname,m.nickname,a.expertid,m.uid from companyresearch as a
left join expertcontact as b on a.expertid=b.expertid
left join members as m on b.email = m.email
left join members as m2 on b.name=m2.nickname
left join company_user as c on m.uid=c.uid
where a.symbol=’000826′ and a.expertid>0 group by m.nickname order by a.time desc limit 0,10

查询只需1秒多一点

发表评论

邮箱地址不会被公开。 必填项已用*标注

13 − 6 =