Return to Snippet

Revision: 10645
at January 7, 2009 15:53 by gfazioli


Updated Code
INSERT INTO MYTABLE SELECT * FROM MYTABLE

/**
 * You can use WHERE clause too
 */

INSERT INTO MYTABLE SELECT * FROM MYTABLE WHERE something=something


/**
 * If you have an unique index... for exmaple id
 */

INSERT INTO MYTABLE (field1, field2, ...) SELECT field1, field2,... FROM MYTABLE

/**
 * If you have to change some value...
 */

INSERT INTO MYTABLE (field1, field2, ...) SELECT (field1+1), field2,... FROM MYTABLE

Revision: 10644
at January 7, 2009 15:52 by gfazioli


Updated Code
INSERT INTO MYTABLE SELECT * FROM MYTABLE

/**
 * You can use WHERE clause too
 */

INSERT INTO MYTABLE SELECT * FROM MYTABLE WHERE something=something


/**
 * If you have an unique index... for exmaple id
 */

INSERT INTO MYTABLE (field1, field2, ...) SELECT (field1, field2,...) FROM MYTABLE

/**
 * If you have to change some value...
 */

INSERT INTO MYTABLE (field1, field2, ...) SELECT (field1+1, field2,...) FROM MYTABLE

Revision: 10643
at January 7, 2009 12:05 by gfazioli


Initial Code
INSERT INTO MYTABLE SELECT * FROM MYTABLE

/**
 * You can use WHERE clause too
 */

INSERT INTO MYTABLE SELECT * FROM MYTABLE WHERE something=something


/**
 * If you have an unique index... for exmaple id
 */

INSERT INTO MYTABLE VALUE(field1, field2, ...) SELECT (field1, field2,...) FROM MYTABLE

/**
 * If you have to change some value...
 */

INSERT INTO MYTABLE VALUE(field1, field2, ...) SELECT (field1+1, field2,...) FROM MYTABLE

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

Initial Description

                                

Initial Title
Duplicate or clone one or more rows in MySQL

Initial Tags
mysql, sql

Initial Language
SQL