View Full Version : Deleting duplicate records in a table


dollarbillg
10-15-2001, 07:52 AM
What I am trying to do is delete duplicate records from a table. I have created a Select statement, below that gives me the dup. records but I now need to delete those form the table.

SELECT DISTINCTROW First([68sdi COPY].DWGNO) AS [DWGNO Field], First([68sdi COPY].ASBUILT) AS [ASBUILT Field], Count([68sdi COPY].DWGNO) AS NumberOfDups
FROM [68sdi COPY]
GROUP BY [68sdi COPY].DWGNO, [68sdi COPY].ASBUILT
HAVING (((Count([68sdi COPY].DWGNO))>1) AND ((Count([68sdi COPY].ASBUILT))>1));

Any and all suggestions would be greatly appreciated. Thanks in advance

Bill

Pat Hartman
10-15-2001, 12:01 PM
The easiest way to clean up this type of mess is to copy the table structure to a new table and set the proper field or fields as the primary key. Then use an append query to copy the data from the old table to the new table. Only the FIRST instance of the duplicate rows will be added to the new table. All the others will be discarded. Just click OK at the end of the append to clear the error message. Once you are sure that nothing important has been lost, rename or delete the original table and rename the new one to the old one's name.