by
0
5
2,801
0
Top 1% !
Popular
Famous
Specified
OpenSource
Popularity: 5739th place
No tags for this snippet yet.
DBMSMS SQL Server
LanguageSQL
LicenseMIT_X11

Removing Duplicated rows from table

Let's use ROW_NUMBER() to purge tables from duplicated data.
You need to identify which set of columns are the unique key and then apply PARTITION over them.
Thanks to Stefan Krzywicki.
http://www.sqlservercentral.com/articles/duplicate+data/102383/
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/11335/Removing-Duplicated-rows-from-table?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
DELETE q FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY Field1, Field2 ORDER BY Field1, Field2) R , Field1 , Field2 FROM DuplicateRow ) q WHERE R > 1
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus