Reputation: 183
anyone know how can i delete duplicate rows by writing new way from script below to improve performance.
DELETE lt1 FROM #listingsTemp lt1, #listingsTemp lt2
WHERE lt1.code = lt2.code and lt1.classification_id > lt2.classification_id and (lt1.fap < lt2.fap or lt1.fap = lt2.fap)
Upvotes: 2
Views: 523
Reputation: 12025
The odiseh answer seems to be valid (+1), but if for some reason you can't alter the structure of the table (because you have not the code of the applications that are using it or something) you could write a job that run every night and delete the duplicates (using the Moayad Mardini code).
Upvotes: 0
Reputation: 9973
Look into BINARY_CHECKSUM .... you could possibly use it when creating your temp tables to more quickly determine if the data is the same.... for example create a new field in both temp tables storing the binary_checksum value... then just delete where those fields equal
Upvotes: 0
Reputation: 7341
Delete Duplicate Rows in a SQL Table :
delete table_a
where rowid not in
(select min(rowid) from table_a
group by column1, column2);
Upvotes: 3
Reputation: 26517
1 - Create an Identity Column (ID) for your table (t1) 2 - Do a Group by on your table with your conditions and get IDs of duplicated records. 3 - Now, simply Delete records from t1 where IDs IN duplicated IDs set.
Upvotes: 1