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

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

 

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

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;
相关文章
相关标签/搜索