Solved

Delete Duplicate query. Deletes duplicates. But I need for it to keep one record once it deletes

Posted on 2013-01-25
7
281 Views
Last Modified: 2013-02-12
Hello, Experts
I have a query that finds the duplicates and deletes them. This works fine. However, it deletes all the duplicates of a certain record. I need for it once it finds a duplicate delete it but just keep one of the records.

Meaning delete all but one, once you find the duplicates.

DELETE [Serial ].*, tblInductionCheckHistory.Serial
FROM tblInductionCheckHistory
WHERE (((tblInductionCheckHistory.Serial) In (SELECT [Serial] FROM [tblInductionCheckHistory] As Tmp GROUP BY [Serial] HAVING Count(*)>1 )));
0
Comment
Question by:gigifarrow
  • 3
  • 3
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38819138
are you deleting the duplicates except one in tblInductionCheckHistory ?


delete *
from tblInductionCheckHistory
where [serial] not in(select min(a.[serial]),[otherfieldwithduplicates] from tblInductionCheckHistory
group by tblInductionCheckHistory.[otherfieldwithduplicates])
0
 
LVL 5

Expert Comment

by:RehanYousaf
ID: 38819139
If you provide some sample data with tabe fields and desired result in excel format ... it will help :-)
0
 

Author Comment

by:gigifarrow
ID: 38826985
Okay here is the table and the query it deletes all the records that have duplicates. I need for it to delete all but one.




example;

serial numbers with duplicates
2334544
2334544
2334544
2468246

wants duplicates deleted it looks like this:
2334544
2468246
Helpdeleteduplicates.zip
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:gigifarrow
ID: 38827017
I dont understand where it says [otherfieldwithduplicates]
what is suppose to be in this field.?

What does the (a) mean in right here:(select min(a.[serial]),[otherfieldwithduplicates]

from tblInductionCheckHistory
where [serial] not in(select min(a.[serial]),[otherfieldwithduplicates] from tblInductionCheckHistory
group by tblInductionCheckHistory.[otherfieldwithduplicates])
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 38827042
you need to add an autonumber field to your table

see this revised db

see query1
Helpdeleteduplicates.accdb
0
 

Author Comment

by:gigifarrow
ID: 38831507
Thank you for your help how come you dont have to Dim a and b. If you have time could you please explain. Just want to understand. So I can do it on my own.

Works great!!
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 38831515
<how come you dont have to Dim a and b>

in a query, you don't need to use DIM

you can use

from tableName AS T

or simply

from TableName  T
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question