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