Forum Discussion
Tony2021
Nov 20, 2021Iron Contributor
Delete Duplicates (leave 1)
Hello, I have duplicates in my table and I want to delete only 1 of them. I have searched on the net for some code and found the below and fashioned it to my case. I have an error though and it appe...
- Nov 20, 2021
Hi
I'm just about to go out but have a look at the 2 example apps in the attached zip file which show two different approaches to thisHope one/both are of help
arnel_gp
Nov 24, 2021Iron Contributor
this is from Allen Browne's site:
DELETE *
FROM [Import_Excel_wRepeats]
WHERE ID1 <> (SELECT Min(ID1) AS MinOfID FROM Table1 AS Dupe
WHERE (Dupe. [Section] = [Import_Excel_wRepeats].[Section]) AND (Dupe.[short description] = Table1.[short description]));
DELETE *
FROM [Import_Excel_wRepeats]
WHERE ID1 <> (SELECT Min(ID1) AS MinOfID FROM Table1 AS Dupe
WHERE (Dupe. [Section] = [Import_Excel_wRepeats].[Section]) AND (Dupe.[short description] = Table1.[short description]));
arnel_gp
Nov 24, 2021Iron Contributor
forgot to change Table1 there:
DELETE *
FROM [Import_Excel_wRepeats]
WHERE ID1 <> (SELECT Min(ID1) AS MinOfID FROM [Import_Excel_wRepeats] AS Dupe
WHERE (Dupe. [Section] = [Import_Excel_wRepeats].[Section]) AND (Dupe.[short description] = [Import_Excel_wRepeats].[short description]));
DELETE *
FROM [Import_Excel_wRepeats]
WHERE ID1 <> (SELECT Min(ID1) AS MinOfID FROM [Import_Excel_wRepeats] AS Dupe
WHERE (Dupe. [Section] = [Import_Excel_wRepeats].[Section]) AND (Dupe.[short description] = [Import_Excel_wRepeats].[short description]));