Duplicate / Copy records in the same MySQL table
- by Digits
Hello,
I have been looking for a while now but I can not find an easy solution for my problem. I would like to duplicate a record in a table, but of course, the unique primary key needs to be updated.
I have this query:
INSERT INTO invoices
SELECT * FROM invoices AS iv
WHERE iv.ID=XXXXX ON DUPLICATE
KEY UPDATE ID = (SELECT MAX(ID)+1 FROM invoices)
the proble mis that this just changes the ID of the row instead of copying the row. Does anybody know how to fix this ?
Thank you verrry much,
Digits
//edit: I would like to do this without typing all the field names because the field names can change over time.