With reference to https://support.microsoft.com/en-us/help/139444/how-to-remove-duplicate-rows-from-a-table-in-sql-server
The idea of removing duplicate involves
- a) Protecting those rows that are not duplicate
- b) Retain one of the many rows that qualified together as duplicate.
Step-by-step
- 1) First identify the rows those satisfy the definition of duplicate
and insert them into temp table, say #tableAll .
- 2) Select non-duplicate(single-rows) or distinct rows into temp table
say #tableUnique.
- 3) Delete from source table joining #tableAll to delete the
duplicates.
- 4) Insert into source table all the rows from #tableUnique.
- 5) Drop #tableAll and #tableUnique