Back
I am new to MySQL. I would like to copy the content of one table to another table within the same database. Basically, I would like to insert a table from another table. Is there an easy way of doing this?
Try using the below query:
INSERT INTO TARGET_TABLE SELECT * FROM SOURCE_TABLE;
But, if the tables have different structures then you can use this query:
INSERT INTO TARGET_TABLE (`col1`,`col2`) SELECT `col1`,`col2` FROM SOURCE_TABLE;
To constrain, use this:
INSERT INTO TARGET_TABLE (`col1_`,`col2_`) SELECT `col1`,`col2` FROM SOURCE_TABLE WHERE `foo`=1
31k questions
32.8k answers
501 comments
693 users