convert query to delete query

I have used the wizard to find duplicate rows in a table but would like a query that can delete one of the duplicates but not sure how.

am working in access 2013.

SELECT First(TVIToMvris.[MvrisCode]) AS [MvrisCode Field], First(TVIToMvris.[TviCode]) AS [TviCode Field], First(TVIToMvris.[Matched By]) AS [Matched By Field], Count(TVIToMvris.[MvrisCode]) AS NumberOfDups
FROM TVIToMvris
GROUP BY TVIToMvris.[MvrisCode], TVIToMvris.[TviCode], TVIToMvris.[Matched By]
HAVING (((Count(TVIToMvris.[MvrisCode]))>1) AND ((Count(TVIToMvris.[Matched By]))>1));

Open in new window

PeterBaileyUkAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott McDaniel (Microsoft Access MVP - EE MVE )Infotrakker SoftwareCommented:
You could convert that to a query that returns a single Field can can point to one (and only one) row from the groups of duplicates, and then write a query like this:

DELETE * FROM YourTable WHERE YourField IN (<the full sql of your query here> OR <SELECT YourFieldName FROM YourSavedQuery here>)
PatHartmanCommented:
There is no good way to do this with a delete query.  The problem being that you can't specifically identify the row(s) to be deleted since they are all duplicates.  You can't select one of the duplicates unless there is a unique identifier and then of course, the rows aren't duplicated.

The best solution is to copy the table structure only.  Add the appropriate unique index or primary key to prevent future duplicates.  Then run an append query to copy the rows from the original table to the new, empty table.  The query will produce an error message at the end telling you that x rows were not added due to "key violations".  Just say OK.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
aikimarkCommented:
You might also have trouble doing this if the inclusion of your Group By query makes the recordset not update-able.  In that circumstance, I convert my Group By query into a pair of DCount() functions.
PeterBaileyUkAuthor Commented:
yes I suggested this to the team that have the table  and they said no but I will work on them anyway its the only really viable simple solution.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.