If the duplicate is being determined by "custname" (rather the column var1) and it looks like there is an ID in there as well, then you can update all dupes in one hit...
Doing what you are currently doing will update every instance of the duplicate to have the same values in var5 - not really getting rid of duplicates, just making all duplicates the same var5 value - is that what you are really trying to do ?
Normally when there is an ID, can run duplicate testing like :
select var1, id
from Ocontacts
where id <> (select max(id) from ocontacts c where c.var1 = ocontacts.var1)
That way it preserves the max(id) and shows the lesser ID's for the same var1 - and it will report on the entire table at the same time...
So, what you might typically do is to "manage" the duplicates leaving one "real" one something like :
update Ocontacts set var5 = 'This is old and a dupe'
from Ocontacts
where id <> (select max(id) from ocontacts c where c.var1 = ocontacts.var1)
Does that make sense ?
Main Topics
Browse All Topics





by: BrandonGalderisiPosted on 2009-10-20 at 20:02:10ID: 25620541
You can read the table definition by querying information_schema.columns to get the list of columns. But you have to specify column names on update.