Resolved merging 2 tables with update and insert

mysiar

Member
Joined
Mar 10, 2009
Messages
7
Programming Experience
Beginner
Hi
I have to tables and need to merge them.
Tables are with the same structure

table1 - fields a,b,c,d
table2 - fields a,b,c,d

a - is a unique key on which I would like to merge them
I would like to update for instance table2 from table1
if key a exists then table2.b = table2.b+table1.b
if do not exist insert the whole record from table1 to table2

Any idea how to do it ?

Regards
Piotr
 
Last edited:
Thanks but I had to do it in the query inside mySQL database.
I googled out something like this:

VB.NET:
insert into `table2`(`a`, `b`, `c`, `d`)
    select `a`,`b`,`c`,`d` from `table1`
    on duplicate key update `b` = `table2`.`b` + `table1`.`b`;

to merge two tables with 1,500,000 records and another one with 270,000
records takes around 7 to 8 seconds and there is no big difference which table
is updated big one or smaller one
 
Back
Top