I have the table behaviour where I count the pages of each hash. I want to transfer the results into a new table new_table.
If the hash on new_table exists, then just update the number of pages.
Otherwhise, if it is a new hash found on behaviour that did not inserted yet to new_table just add it.
INSERT INTO new_table (hash, pages)
SELECT hash, COUNT( id ) AS pages
FROM behaviour
ON DUPLICATE KEY UPDATE new_table.pages=behaviour.pages
GROUP BY hash
I get an error on the 5th line "group by hash". What am I doing wrong?
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GROUP BY hash' at line 5