0

I'd like to copy the content to an existing table to another existing table. This is what I've tryed :

INSERT into memoryTable select * from currentTable

but I get this error message : #1062 - Duplicate entry '1' for key 'memoryTable.PRIMARY'

jarlh
  • 42,561
  • 8
  • 45
  • 63

1 Answers1

0

For the persons who have the same problem, I've found a solution :

REPLACE
INTO memoryTable
SELECT *
FROM currentTable
;
  • fyi - If there is a duplicate/existing primary key, `replace` will overwrite values in `memoryTable` with the conflicting values from `currentTable`. If you would rather keep the existing values in `memoryTable`, you can use `insert ignore into memoryTable...` See also [Difference between insert ignore and replace](https://stackoverflow.com/questions/4723145/what-is-the-performance-difference-between-insert-ignore-and-replace-in-mysql) – akenney Jan 06 '23 at 19:59
  • 1
    [A code-only answer is not high quality](//meta.stackoverflow.com/questions/392712/explaining-entirely-code-based-answers). While this code may be useful, you can improve it by saying why it works, how it works, when it should be used, and what its limitations are. Please [edit] your answer to include explanation and link to relevant documentation. – Stephen Ostermiller Jan 06 '23 at 20:09