如何从表中删除重复的行?
答案 0 :(得分:2)
我喜欢CTE和ROW_NUMBER,因为它允许轻松更改它以查看哪些行被删除(或更新),因此只需将DELETE FROM CTE ...更改为SELECT * FROM CTE:
;WITH CTE AS (
SELECT [col1],
[col2],
[col3],
[col4],
[col5],
[col6],
[col7],
RN = ROW_NUMBER() OVER (PARTITION BY col1 ORDER BY col1)
FROM dbo.table
)
DELETE FROM CTE
WHERE RN > 1
试试这个