MySQL Duplicate Rows With Updates


/ Published in: MySQL
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. CREATE table temporary_table AS SELECT * FROM sometable WHERE website_id=4;
  2.  
  3. UPDATE temporary_table SET website_id=5;
  4.  
  5. UPDATE temporary_table SET sometable_primary_key_id=NULL;
  6.  
  7. INSERT INTO sometable
  8. SELECT * FROM temporary_table;
  9. DROP table temporary_table;

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.