PDA

View Full Version : Update without adding duplicates.



mud2
10-06-2008, 03:02 PM
No, not a simple DISCRETE problem:
I have two tables, TableA And tableB
TableA has a list of names, and the number of times each name has been added to the table. TableB has another list of names...some also on TableA, some not. I want to add those names from B to A that are NOT on A, but increase the number if times a duplicate would have been added.

TableA
Owen 5
George 2
Henry 1

TableB
Owen
Smitty
Harry

TableA After process
Owen 6
George 2
Henry 1
Smitty 1
Harry 1

And sometimes I might want to REMOVE some names from TableA, and not All...ie. Owen might go from 6 to 5.

Randy???

ottoS13
10-06-2008, 04:26 PM
are you doing this in vba or in a query?

you would use a "not in" query to get ones that were not in table a but in table b

mud2
10-06-2008, 06:32 PM
I've done this in VBA, but think that it (might) be simpler in SQL.
If I use a "not in", how do I increment (decrement) the count for the number of times a name has been entered into the table?

The Isaac
10-07-2008, 06:23 AM
Check the syntax, but this should give you the idea:

currentproject.connection.excecute "INSTERT INTO TableA ([name]) SELECT ([name]) FROM TableB left join tableA on Tableb.name <> tableA.name where tablea.name is null"

currentproject.connection.excecute "UPDATE TableA set [count] = count(name) from TableB where tablea.name = tableb.name"