How to delete duplicate record where PK is uniqueidentifier field
I want to know the way we can remove duplicate records where PK is uniqueidentifier. I have to delete records on the basis of duplicate values in a set of fields.we can use option to get temptable using Row_Number() and except row number one we can delete rest or the records. But I wanted to build one liner query. Any suggestion?
You can use CTE to do this, without seeing your table structure here is the basic SQL
;with cte as ( select *, row_number() over(partition by yourfields order by yourfields) rn from yourTable ) delete from cte where rn > 1