I'm having a brain fart and for some reason it's not coming to me how to do this right now.
I'm trying to tally up a table, and store the results in a different table. Like so
user score ---- ----- 1 4 1 5 1 2 2 1 2 3 ...
And now I want to tally that up and put it into the following table:
user total_score ---- ----------- 1 ? 2 ?
I know it can be done with a single MySQL query with a subquery, but I didn't get much sleep last night :)
INSERT INTO table2 (user, total_score) SELECT ( user, SUM(score) FROM table1 GROUP BY user )
But wait ... what if I just wanted to update the total_score column??
What's the proper syntax to update existing rows where user is a primary key in both tables?