I have the following:
table1:
+-----+-----+-------+
| nid | vid | count |
+-----+-----+-------+
| 1 | 1 | 15 |
| 1 | 2 | 5 |
| 2 | 3 | 7 |
+-----+-----+-------+
I'm looking for an SQL query that can do an INSERT ... SELECT statement to give me this:
table2:
+-----+-------------+
| nid | total_count |
+-----+-------------+
| 1 | 20 |
| 2 | 7 |
+-----+-------------+
Possible using just SQL?
INSERT INTO table2 (nid, total_count) SELECT DISTINCT (nid), SUM(total_count) FROM table1 WHERE table2.nid = table1.nid
doesn't work....