Mysql will be a table of content into another table

Category it, if the same two tables (export and destination tables) field, and want to insert all data, this method can be used:

INSERT INTO target table SELECT * FROM source table;

For example, to insert into Table A Table B, can be achieved by the following SQL statement:

INSERT INTO A SELECT * FROM B ;

Category 2, if you only want to import specified field, this method can be used:

INSERT INTO target table (Field 1, Field 2, ...) SELECT field 1, field 2, ... FROM table origin;

Please note that the above two tables of field types must be the same data conversion error.

Category III.

① If tables TABLE_A, TABLE_B import data in the third table TABLE_C

INSERT INTO TABLE_C SELECT * FROM TABLE_A UNION  ALL SELECT * FROM TABLE_B;

INSERT INTO TABLE_C (column1,column2,……) SELECT column1,column2,……FROM TABLE_A UNION ALL SELECT column1,column2,……FROM TABLE_B;

② If tables TABLE_A, TABLE_B third table TABLE_C data lead, and remove duplicate data:

INSERT INTO TABLE_C SELECT * FROM TABLE_A UNION  SELECT * FROM TABLE_B;

INSERT INTO TABLE_C (column1,column2,……) SELECT column1,column2,……FROM TABLE_A UNION  SELECT column1,column2,……FROM TABLE_B;

 

Guess you like

Origin www.cnblogs.com/yaoze2018/p/11329892.html