开发者

Compare two tables, if not exists update or insert

开发者 https://www.devze.com 2023-01-31 11:23 出处:网络
I have a two same tables.Database mysql. How can I compare two tables? Table1,Table2 - the same.. differences only in开发者_运维技巧 rows

I have a two same tables.Database mysql.

How can I compare two tables?

Table1,Table2 - the same.. differences only in开发者_运维技巧 rows

IF in one table id key exists,update row.If key is not exists insert new row.

Thanks.


One option might be to use REPLACE, which is like INSERT, except that existing rows 'in the way' are deleted before the insert.

There's also INSERT ON DUPLICATE KEY UPDATE which is somewhat similar - does what you suggest.


upsert http://www.xaprb.com/blog/2006/06/17/3-ways-to-write-upsert-and-merge-queries-in-mysql/

0

精彩评论

暂无评论...
验证码 换一张
取 消