Avatar of Bevos
Bevos

asked on 

Delete a single duplicate from a pair of duplicates SQL query

Hello, I have a query that finds duplicate values from my database but doesnt' do anything about them.  I would like someone to show me how to change the code so that only a single record of the duplicates remains.  I don't care which one, because these are all functionally identical entries.  

Thanks,
Bevo



SELECT DISTINCT First(Imported.Author2) AS [Author2 Field], First(Imported.Year) AS [Year Field], First(Imported.TitleShrt) AS [TitleShrt Field], First(Imported.Volume) AS [Volume Field], Count(Imported.Author2) AS NumberOfDups
FROM Imported
GROUP BY Imported.Author2, Imported.Year, Imported.TitleShrt, Imported.Volume
HAVING (((Count(Imported.Author2))>1) AND ((Count(Imported.Volume))>1));

Open in new window

Microsoft AccessMySQL Server

Avatar of undefined
Last Comment
Bevos
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

do you have a unique id field?

delete * from tablex
where [id] not in(select min([id]) from tablex)
the unique id field is the field [id] in the query posted above.

create a backup coy of the table before running the delete query
missing some part in the query

delete * from tablex
where [id] not in(select min([id]) from tablex as A where A.Field1=tablex.field1 and A.field2=tablex.field2)
Avatar of Bevos
Bevos

ASKER

Hi Capricorn1, the duplicate entries have different IDs (this is an autonumber field and they were imported afterward)
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Bevos
Bevos

ASKER

This worked beautifully.  

Thank you so much,
Bevo
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo