如何合并两个MySQL表?(How can I merge two MySQL tables?)
如何合并两个具有相同结构的MySQL表?
两个表的主键将会冲突,所以我考虑到这一点。
How can I merge two MySQL tables that have the same structure?
The primary keys of the two tables will clash, so I have take that into account.
最满意答案
你也可以试试:
INSERT IGNORE INTO table_1 SELECT * FROM table_2 ;这允许table_1中的那些行取代了具有匹配主键的table_2中的行,同时仍然使用新的主键插入行。
或者,
REPLACE INTO table_1 SELECT * FROM table_2 ;将使用table_2中的相应行更新table_1中已经存在的行,同时使用新的主键插入行。
You can also try:
INSERT IGNORE INTO table_1 SELECT * FROM table_2 ;which allows those rows in table_1 to supersede those in table_2 that have a matching primary key, while still inserting rows with new primary keys.
Alternatively,
REPLACE INTO table_1 SELECT * FROM table_2 ;will update those rows already in table_1 with the corresponding row from table_2, while inserting rows with new primary keys.
更多推荐
发布评论