Duplicate or clone one or more rows in MySQL


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



Copy this code and paste it in your HTML
  1. INSERT INTO MYTABLE SELECT * FROM MYTABLE
  2.  
  3. /**
  4.  * You can use WHERE clause too
  5.  */
  6.  
  7. INSERT INTO MYTABLE SELECT * FROM MYTABLE WHERE something=something
  8.  
  9.  
  10. /**
  11.  * If you have an unique index... for exmaple id
  12.  */
  13.  
  14. INSERT INTO MYTABLE (field1, field2, ...) SELECT field1, field2,... FROM MYTABLE
  15.  
  16. /**
  17.  * If you have to change some value...
  18.  */
  19.  
  20. INSERT INTO MYTABLE (field1, field2, ...) SELECT (field1+1), field2,... FROM MYTABLE

URL: http://www.undolog.com/2009/01/07/very-short-trick-duplicare-o-clonare-una-o-pia-righe-in-mysql/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.