Compare two tables, if not exists update or insert
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/
精彩评论