Skip to content

Instantly share code, notes, and snippets.

@stemwinder
Last active July 13, 2016 15:19
Show Gist options
  • Save stemwinder/be9b3032c5a8e7b08e3933bc80a2bbcb to your computer and use it in GitHub Desktop.
Save stemwinder/be9b3032c5a8e7b08e3933bc80a2bbcb to your computer and use it in GitHub Desktop.
Duplicate / Copy rows in MySQL table
-- 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