Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@anvyst
Created February 10, 2014 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anvyst/8917113 to your computer and use it in GitHub Desktop.
Save anvyst/8917113 to your computer and use it in GitHub Desktop.
Copy-paste specific row in MySQL
# YOURID - source record
# yourtable - target table;
CREATE TEMPORARY TABLE tmp_table SELECT * FROM yourtable WHERE id=YOURID;
SELECT @new_id:=((SELECT id FROM yourtable ORDER BY id DESC LIMIT 1) + 1);
UPDATE tmp_table SET id=@new_id WHERE id =YOURID;
INSERT INTO yourtable SELECT * FROM tmp_table WHERE id=@new_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment