Hi All, I am trying to delete the duplicates from a table, but keep 1 of the records. Here is my query which works on smaller tables <2000 records, but the query either timeouts or just runs and runs on larger tables >50,000 and >150,000.DELETE FROM Table1WHERE Table1.ID IN /* LIST 1 - all rows that have duplicates*/ (SELECT F.ID FROM Table1 AS F WHERE EXISTS ( SELECT computerName, programName, version, publisher, Count(ID) FROM Table1 WHERE Table1.computerName = F.computerName AND Table1.programName = F.programName AND Table1.version = F.version AND Table1.publisher = F.publisher GROUP BY Table1.computerName, Table1.programName, Table1.version, Table1.publisher HAVING Count(Table1.ID) > 1)) AND Table1.ID NOT IN/* LIST 2 - one row from each set of duplicate*/ (SELECT Min(ID) FROM Table1 AS F WHERE EXISTS ( SELECT computerName, programName, version, publisher, Count(ID) FROM Table1 WHERE Table1.computerName = F.computerName AND Table1.programName = F.programName AND Table1.version = F.version AND Table1.publisher = F.publisher GROUP BY Table1.computerName, Table1.programName, Table1.version, Table1.publisher HAVING Count(Table1.ID) > 1) GROUP BY computerName, programName, version, publisher);
TABLE STRUCTURE::ID computerName programName version publisher installDate1 COMP1 Microsoft .NET Framework 1.1 1.1.4322 Microsoft 200502162 COMP1 Windows XP Hotfix - KB891781 20050110.17 Microsoft NULL3 COMP1 Windows Media Player 10 NULL NULL NULL4 COMP1 Microsoft .NET Framework 1.1 1.1.4322 Microsoft 02/16/2005The duplicate records i am trying to delete are not truly duplicates, each record has a unique ID and install dates could vary. I am trying to identify duplicate records as identical (computerName + programName + version + publisher) See records 1 and 4 in table structure above... i dont care which of the duplicates is kept, as long as 1 is kept. What I am looking for is either a completely new query which maybe optimized to run on a larger scale table or maybe just a performance tweak to my exisitng query??Any help would be greatly appreciated!Thanks.