Saqib Ali
Saqib Ali

Reputation: 12545

How can I duplicate all the rows of a table into the same table?

I have a mysql table with 20 fields and only 5 rows. None of the fields are unique, indexed or primary keys.

I want to simply duplicate all 5 rows in the table. Is there a single SQL statement to do this?

Upvotes: 0

Views: 59

Answers (1)

Jimish Gamit
Jimish Gamit

Reputation: 1024

Following query should fulfill your requirement

INSERT INTO TABLE1 SELECT * FROM TABLE1;

If you want to copy all fields from another table then,

INSERT INTO TABLE1 SELECT * FROM TABLE2;

If you want to copy only specific fields then,

INSERT INTO TABLE1(field1,field2) SELECT field1,field2 FROM TABLE2;

Please note that field count in INSERT and SELECTshould be the same.

Upvotes: 2

Related Questions