I have an interesting problem, that i am sure has a simple answer, but i can’t seem to find it in the docs.
I have two separate database tables, on different servers. They are both identical table schema with the same primary keys.
I want to merge the tables together on one server. But, if the row on Server1.Table1 exists in Server2.Table2 then sum up the totals in the columns i specify.
Table1{
column_pk, counter
};
“test1”, 3
“test2”, 4
Table2{
column_pk, counter
};
“test1”, 5
“test2”, 6
So after i merge i want:
“test1”,8
“test2”,10
Basically i need to do a mysqldump but instead of it kicking out raw INSERT statements, i need to do a INSERT..ON DUPLICATE KEY UPDATE statements.
What are my options?
Appreciate any input, thank you
Where
4andtestare replaced by your actual data.As for how you can achieve an export file containing those queries, I’d suggest you use regular expressions to modify a standard export. Or insert both of them in the same table and the sum them up like suggested by Anax