Reputation: 9546
I'm using Access 2007.
I have a table with about 20 fields. One of those fields is an autonumber ID, so it's unique. I have a lot of records in this table that only differ in their autonumber ID. I can't just delete the ones with odd or even IDs, because some pairs of duplicates have both odds or both evens. Any ideas on how to select one record from each pair for deletion?
I know this could probably be done with VBA, but I'm not really familiar with Access VBA yet, so I'm looking for a purely SQL-based solution.
Upvotes: 1
Views: 2977
Reputation: 115630
DELETE *
FROM yourTable
WHERE id NOT IN
( SELECT min(id)
FROM yourTable
GROUP BY field2
, filed3
, field4
, etc... <--- all other fields, except id
)
Upvotes: 3
Reputation: 16673
delete the ones that are not min(id), grouped by the other columns that mean equivalence.
Upvotes: 2