APAGAR REGISTROS DUPLICADOS, MANTER SOMENTE UM (SQL)

16 de janeiro de 2022   |   by administrador
--VERIFICAR
  WITH CTE AS(
   SELECT *,
       RN = ROW_NUMBER()OVER(PARTITION BY COLUNA ORDER BY COLUNA)
   FROM TABELA
)
Select * FROM CTE WHERE RN > 1

--DELETAR
  WITH CTE AS(
   SELECT *,
       RN = ROW_NUMBER()OVER(PARTITION BY COLUNA ORDER BY COLUNA)
   FROM TABELA
)
DELETE FROM CTE WHERE RN > 1
Tags: