2

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)
1
  • Apologies, but I don't understand the question. Can you clarify "by writing new way from script below"? Also, do you want to do this only once, or on an on going basis, if on going, can you modify the schema and add an identity column? Commented Jun 29, 2009 at 8:55

4 Answers 4

3

Delete Duplicate Rows in a SQL Table :

delete table_a
where rowid not in 
(select min(rowid) from table_a 
group by column1, column2);
Sign up to request clarification or add additional context in comments.

2 Comments

There is no rowid in sql-server!
1

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.

Comments

0

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

Comments

0

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).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.