Daily Shaarli

All links of one day in a single page.

Previous day

February 7, 2019

Next day

T-SQL: Deleting all duplicate rows but keeping one [duplicate]
thumbnail

You didn't say what version you were using, but in SQL 2005 and above, you can use a common table expression with the OVER Clause. It goes a little something like this:

WITH cte AS (
SELECT[foo], [bar],
row_number() OVER(PARTITION BY foo, bar ORDER BY baz) AS [rn]
FROM TABLE
)
DELETE cte WHERE [rn] > 1