Solved

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

Posted on 2013-01-25
7
285 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 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