Duplicate / Copy records in the same MySQL table
        Posted  
        
            by 
                Digits
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Digits
        
        
        
        Published on 2009-04-08T11:01:58Z
        Indexed on 
            2012/06/26
            21:16 UTC
        
        
        Read the original article
        Hit count: 192
        
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 problem is 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.
© Stack Overflow or respective owner