WITH CTE AS(
SELECT [col1], [col2], [col3], [col4], [col5], [col6], [col7],
RN = ROW_NUMBER()OVER(PARTITION BY col1 ORDER BY col1)
FROM dbo.Table1
)
DELETE FROM CTE WHERE RN > 1
http://stackoverflow.com/questions/18390574/how-to-delete-duplicate-rows-in-sql-server
This example determines duplicates by a single column col1
because of the PARTITION BY col1
. If you want to include multiple columns simply add them to the PARTITION BY
:
ROW_NUMBER()OVER(PARTITION BY Col1, Col2, ... ORDER BY OrderColumn)
WITH CTE AS
(
SELECT *,RN=ROW_NUMBER() OVER (PARTITION BY orgName ORDER BY orgName DESC) FROM organizations
)
select * from CTE where RN>1
go
WITH CTE (Code, n, DuplicateCount)
AS
(
SELECT Code, n,
ROW_NUMBER() OVER(PARTITION BY Code, n
ORDER BY Code) AS DuplicateCount
FROM dbo.TestTable
)
SELECT *
FROM CTE
ORDER BY Code, n, DuplicateCount
GO
SELECT Number, MIN(c1) AS c1, MIN(c2) AS c2, MIN(c3) AS c3
FROM [table]
GROUP BY Number
HAVING COUNT(*) = 1
https://stackoverflow.com/questions/40682070/select-only-those-rows-which-occur-exactly-once