Return to Snippet

Revision: 65803
at January 21, 2014 04:26 by donkeykong


Updated Code
CREATE table temporary_table AS SELECT * FROM sometable WHERE website_id=4;

UPDATE temporary_table SET website_id=5;

UPDATE temporary_table SET sometable_primary_key_id=NULL;

INSERT INTO sometable
SELECT * FROM temporary_table;
DROP table temporary_table;

Revision: 65802
at January 21, 2014 04:23 by donkeykong


Initial Code
CREATE table temporary_table AS SELECT * FROM test WHERE website_id=4;

UPDATE temporary_table SET website_id=5;

UPDATE temporary_table SET test_id=NULL;

INSERT INTO test 
SELECT * FROM temporary_table;
DROP table temporary_table;

Initial URL
http://stackoverflow.com/questions/2783150/mysql-how-to-copy-rows-but-change-a-few-fields

Initial Description
I found this script and tried it. It worked. I thought it was useful for a variety of situations and is easy to follow.

Often times I need nearly duplicated data and don't want to manually cut and paste.

Initial Title
MySQL Duplicate Rows With Updates

Initial Tags
mysql

Initial Language
MySQL