Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find AND DELETE Duplicates

Status
Not open for further replies.

MisterC

IS-IT--Management
Apr 19, 2001
501
US
Hi,
I have a query that finds duplicate records in my table. I need a query that will delete (just) the duplicates. Can anyone help me with the sql?
Here's what I have so far:
Code:
SELECT CKNumber, CKDate, CheckAmount 
FROM CKREGISTER
WHERE (((CKNumber) In (SELECT [CKNumber] FROM [CKREGISTER] As Tmp GROUP BY [CKNumber] HAVING Count(*)>1 )))
ORDER BY CKREGISTER.CKNumber;
Thanks for your help.
 
Try:

Delete *
FROM CKREGISTER
WHERE (((CKNumber) In (SELECT [CKNumber] FROM [CKREGISTER] As Tmp GROUP BY [CKNumber] HAVING Count(*)>1 )))

I strongly recommend backing up your table before you try this! You never know...

Also, you can preview the records that will be deleted before you actually run the query
 
Give this SQL a try:

Delete A.CKNumber
FROM CKREGISTER as A
WHERE (((A.CKNumber) In (SELECT [CKNumber] FROM [CKREGISTER] As Tmp GROUP BY [CKNumber] HAVING Count(*)>1 )))
ORDER BY CKREGISTER.CKNumber;

Let me know if you need more help.
Bob Scriver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top