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;
  3. UPDATE temporary_table SET website_id=5;
  5. UPDATE temporary_table SET sometable_primary_key_id=NULL;
  7. INSERT INTO sometable
  8. SELECT * FROM temporary_table;
  9. DROP table temporary_table;


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.