Thursday 21 February 2013

delete duplicate record from table



WITH tablealias (id, DuplicateCount)
AS
(
SELECT id,ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS DuplicateCount FROM emp
)
DELETE FROM tablealias WHERE DuplicateCount > 1
go

//with sub query
select * from (
SELECT id,ROW_NUMBER() OVER(PARTITION BY id ORDER BY id) AS DuplicateCount FROM emp
)tt where DuplicateCount>1

// we can take more than one fields with table

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...