How to delete by row number in SQL

Tim Wilcox picture Tim Wilcox · Oct 6, 2017 · Viewed 29.9k times · Source

I need to delete from row number 475 to 948 due to them being duplicates of rows 1-474. It would be something close to this, I presume, or is there more to it?

DELETE FROM dbo.industry WHERE row_number between 475 and 948

Answer

fly_ua picture fly_ua · Mar 5, 2018

May be it is too late, but I am usually doing this

; with cte(rownum)as(
    select row_number () over(partition by [Col1], [Col2] order by Col3) from [table]
)
delete from cte where rownum > 1