您的位置:首页 > 数据库 > MySQL

使用mysql update join优化update in的查询效率

2016-05-20 00:00 701 查看
摘要: 使用mysql update join优化update in的查询效率

使用mysql update join优化update in的查询效率

有时候更新某个表可能会涉及到多张数据表,例如:

update table_1 set score = score + 5 where uid in (select uid from table_2 where sid = 10);

其实update也可以用到left join、inner join来进行关联,执行效率更高,把上面的sql替换成join的方式如下:

update table_1 t1 inner join table_2 t2 on t1.uid = t2.uid set score = score + 5 where t2.sid = 10;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  mysql update join