简体   繁体   中英

how to combine multiple tables into 1 with mysql

I have a Mysql DB with 4 tables, with same structure and I need to merge all of this tables in a 1 table.

There are 7 fields that are the same in all tables.

Is there any way to merge the tables ?

Thank you very much

If you want just to query all the data from the tables and present them into one set of results you can try the following:

SELECT * FROM table1
UNION
SELECT * FROM table2
UNION
SELECT * FROM table3
UNION
SELECT * FROM table4

If you actually want to transfer all the data from table2, table3, table4 to table1 you can try something like the following:

INSERT INTO table1 (Col1, Col2...col7)
SELECT * FROM table1
UNION
SELECT * FROM table2
UNION
SELECT * FROM table3
UNION
SELECT * FROM table4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM