I’d like to use the ‘insert into’ mysql command to move table1 contents to table2, but table2 may have the ‘same’ primary keys. I want to replace the table2’s record (that have the same primary key) with table1’s record when the insert statement is executed. Can I use ‘or replace’ to make this happen?
Share
Use an INSERT … SELECT with an ON DUPLICATE KEY UPDATE clause:
note using * for brevity, but in the update clause you must specify the fields individually, and should do so in the insert and select clauses as well.