In MySQL, how to copy the content of one table to another table within the same database?

If the tables have the same structure:

INSERT INTO TARGET_TABLE SELECT * FROM SOURCE_TABLE;

If the tables have different structures:

INSERT INTO TARGET_TABLE (`col1`,`col2`) SELECT `col1`,`col2` FROM SOURCE_TABLE;

You can also add conditions:

INSERT INTO TARGET_TABLE (`col1_`,`col2_`) SELECT `col1`,`col2` FROM SOURCE_TABLE WHERE `foo`=1

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)