I think there are two issues here:
1. When you try to create a Deletion query from a select query that joins
the basic table with a Find Duplicates query based on the same table, the
deletion will not run. You will also see that the basic query (the Select
query that joins the table and the find-duplicates query) is not updateable.
2. When you do perform the deletion, you probably don't want to delete all
the records that are duplicated, only some of them; presumably you want to
leave one copy.
You were on the right track by creating a First Of query for the duplicates,
but in order to get the deletion done, you need to use a sub-query, and you
will need to add a primary key to your basic table. I think most folks here
would recommend that you ALWAYS use an Autonumber primary key in your
tables, even if you don't see an obvious use for it when you start out --
I've never regretted it.
Try this (I'm translating from queries that work for me to SQL statements
that I think use your table and field names, so beware of typos: the idea
works)
0. Back up your data.
1. Add an Autonumber primary key field to your table (the table is "MDV",
right? So let's say you name it MDV_ID)
2. Create a Find Duplicates query to find duplicates of [Account Number]
in MDV. It should look like this:
SELECT MDV_ID, [AccountNumber]
FROM MDV
WHERE ((([AccountNumber]) In (SELECT [AccountNumber] FROM [MDV] As Tmp
GROUP BY [AccountNumber] HAVING Count(*)>1 )))
ORDER BY [AccountNumber];
Access will give this query a name like "Find Duplicates for MDV" or
something similar
3. Create a new query based on the find duplicates query, grouping on
Account Number and finding the First MDV_ID. It should look something like
this:
SELECT [Account Number], First([MDV_ID]) AS FirstOfMDV_ID
FROM [Find duplicates for MDV]
GROUP BY [Account Number];
Save this query as qryFirstAcctDupes
4. Now (and finally!) create a deletion query for your MDV table by
dragging the asterisk into the first column and changing the query type to
delete. Then drag the MDV_ID field to the second column, and in the
criterion row type:
In (Select FirstOfMDV_ID From qryFirstAcctDupes)
The complete query SQL should look something like this:
DELETE *
FROM MDV
WHERE (((MDV_ID) In (Select [FirstOfMDV_ID] From qryFirstAcctDupes)));
When you click the Run button, this query should delete some presumably
large number of records, but if you have situations where there were more
than two records with the same Account Number, you will need to run the
query again, maybe several times, to get rid of all of them. Eventually you
will find that the query reports that it is about to delete 0 records, and
then you're done!
HTH
Cheyenne said:
No I haven't. Could you please give instructions on how to do this? Thanks.
:
Cheyenne wrote:
I need a quick way to remove duplicates that are found with the Duplicate
Query. I have been using the "select each record and delete" method.
There
has to be a quicker and easier way. Please help
Cheyenne, Have you tried to create a Delete query based on a Duplicate
Sub-Query?
-Randy