Feeds:
Posts
Comments

Posts Tagged ‘remove duplicates sql server’

CREATE
TABLE  tbl

(

ID 
INT IDENTITY(1,1),

NAME
VARCHAR(100)

)

GO

 

INSERT
tbl

SELECT
‘NAME1’

UNION ALL

SELECT
‘NAME1’

UNION ALL

SELECT
‘NAME2’

GO

 

 

WITH
CTE_Duplicate

AS

(

SELECT
Rank=ROW_NUMBER() OVER ( PARTITION BY
NAME ORDER
BY NAME),*

FROM
tbl

)

 

DELETE
FROM CTE_Duplicate

WHERE
Rank>1

GO

 

 

 

 

Read Full Post »

%d bloggers like this: