Posted By

gfazioli on 01/07/09


Tagged

mysql select sql insert


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

gfazioli


Duplicate or clone one or more rows in MySQL


 / Published in: SQL
 

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

  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

Report this snippet  

You need to login to post a comment.