Skip to main content

Delete duplicate records from the table SQL


 WITH cte AS (    

   SELECT [ITEMID]

      ,[PURCHPRICE]

      ,[RETAILAMDISCOUNTTYPE]

      ,[CURRENCYCODE]

      ,[PURCHDISCPERCENT]

      ,[SALESPRICE]

      ,[VENDACCOUNT]

      ,[FROMDATE]

      ,[TODATE]

      ,[RETAILPRICECHANGESTATUS]

      ,[GROUPID] ,    

   row_number() OVER(PARTITION BY [ITEMID]

      ,[PURCHPRICE]

      ,[RETAILAMDISCOUNTTYPE]

      ,[CURRENCYCODE]

      ,[PURCHDISCPERCENT]

      ,[SALESPRICE]

      ,[VENDACCOUNT]

      ,[FROMDATE]

      ,[TODATE]

      ,[RETAILPRICECHANGESTATUS]

      ,[GROUPID]  order by [ITEMID] ) AS [rn]    

   FROM [RETAILPRICECHANGETABLE]    

)    

DELETE cte WHERE [rn] > 1  

Comments

Post a Comment