Skip to content

Instantly share code, notes, and snippets.

@matheus-santos
Last active October 11, 2018 21:22
Show Gist options
  • Save matheus-santos/7ab7dd01ddfaaacb2d897e641af24fbc to your computer and use it in GitHub Desktop.
Save matheus-santos/7ab7dd01ddfaaacb2d897e641af24fbc to your computer and use it in GitHub Desktop.
Duplicate row in MySQL
-- Replace `{{TABLE_NAME}}` to desired table
-- Replace `{{ID}}` to desired row you want to replace
create temporary table `temp` select * from `{{TABLE_NAME}}` where id = {{ID}};
update `temp` SET id = (select id from {{TABLE_NAME}} order by id desc limit 1) + 1 where id = {{ID}};
insert into `{{TABLE_NAME}}` select * from `temp`;
drop TEMPORARY table if exists `temp`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment