Perform updates on a single table nothing more to say than to update table_name set col1 = Xx,col2 = yy where col = zz, which is mainly the setting of the Where condition. Sometimes updating a table may involve more than one datasheet, for example:
The code is as follows |
Copy Code |
Update Table_1 Set score = score + 5 where UID in (select UID from table_2 where sid = 10); In fact, update can also be used to the left join, inner join to the association, may be more efficient, the above SQL to replace the join method as follows: Update table_1 t1 INNER join table_2 t2 on t1.uid = T2.uid Set score = score + 5 where T2.sid = 10; |
MySQL Association Multiple tables for update operations
code is as follows |
copy code |
UPDATE Track INNER JOIN MV on Track.trkid=mv.mvid SET track.is_show=mv.is_show WHERE trkid<6 equals /p> UPDATE track,mv SET track.is_show=mv.is_show WHERE track.trkid=mv.mvid and trkid<6 |