Last active
July 13, 2016 15:19
-
-
Save stemwinder/be9b3032c5a8e7b08e3933bc80a2bbcb to your computer and use it in GitHub Desktop.
Duplicate / Copy rows in MySQL table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://stackoverflow.com/a/8077952/3530438 | |
CREATE TEMPORARY TABLE tmp SELECT * from invoices WHERE ...; | |
ALTER TABLE tmp drop ID; # drop autoincrement field | |
# UPDATE tmp SET ...; # just needed to change other unique keys | |
INSERT INTO invoices SELECT 0,tmp.* FROM tmp; | |
DROP TABLE tmp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment