Last active
October 11, 2018 21:22
-
-
Save matheus-santos/7ab7dd01ddfaaacb2d897e641af24fbc to your computer and use it in GitHub Desktop.
Duplicate row in MySQL
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
-- 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