MySql update two tables at once

It should be possible with a multi-table update, as described in the documentation.

http://dev.mysql.com/doc/refman/5.5/en/update.html

UPDATE Table_One a INNER JOIN Table_Two b ON (a.userid = b.userid)
SET
  a.win = a.win+1, a.streak = a.streak+1, a.score = a.score+200,
  b.win = b.win+1, b.streak = b.streak+1, b.score = b.score+200 
WHERE a.userid = 1 AND a.lid = 1 AND b.userid = 1

Note: Multi-table doesn't support LIMIT, so this could cause more grief depending on the details.

Stored procedures or transactions may be a nicer solution.


If there is a one to one or one to many relation from Table_One to Table_Two, this would work:

UPDATE Table_One T1, Table_Two T2 
SET T1.win = T1.win+1, T1.streak = T1.streak+1, T1.score = T1.score+200, 
    T2.win = T2.win+1, T2.streak = T2.streak+1, T2.score = T2.score+200 
WHERE T1.userid = 1 AND T1.lid = 1 AND T2.userid = T1.userid;