如何合并两个MySQL表?(How can I merge two MySQL tables?)

编程入门 行业动态 更新时间:2024-10-25 16:21:48
如何合并两个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.

更多推荐

本文发布于:2023-08-05 05:27:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1427985.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   MySQL   tables   merge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!