voodoochicken Posted March 17, 2008 Share Posted March 17, 2008 hi, i have a case like this:table table1 (key, accumulator)table table2 (key, counter)i want to, for each table1.key = table2.key, update accumulator with the info in counter, something like this:update table1 set accumulator=accumulator+table2.counter where (? counter is the value related with the same key as the one in table1)how do you write a sentence like this one?tnx------(EDIT) note: not all keys in table1 are present in table2 Link to comment Share on other sites More sharing options...
voodoochicken Posted March 17, 2008 Author Share Posted March 17, 2008 i was checking the mysql reference manual (which can be downloaded from mysql.com) and it seems the update statement can accept more than one table. it may be what i was looking for (still reading) Link to comment Share on other sites More sharing options...
justsomeguy Posted March 19, 2008 Share Posted March 19, 2008 I haven't checked any syntax, so I'm pretty much just pulling this out, but it might work:UPDATE table1 INNER JOIN table2 ON table1.key=table2.key SET accumulator=accumulator+counter Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.