Thursday, November 6, 2014

Lesson 37: Copy data into another table (as new table) in mysql

UPDATE:
i just found out a better way to do this:
CREATE TABLE newTable LIKE oldTable;
INSERT newTable SELECT * FROM oldTable;
---------------
for tables with same schema:
INSERT INTO newTable
SELECT * FROM oldTable
Otherwise, you'll have to specify column names:
INSERT INTO newTable (col1, col2, col3)
SELECT column1, column2, column3
FROM oldTable

Reference :
http://stackoverflow.com/questions/13237623/copy-data-into-another-table

No comments:

Post a Comment