sql server - SQL Delete duplicate rows with lowest number -
i can't find appropriate way delete duplicate keys in sql table lowest number. if there duplicate rows same number, need delete 1 of them.
for example
key number description 11111 5 desc1 11111 4 desc2 22222 2 desc1 22222 2 desc2 33333 3 desc1 33333 5 desc2
here need deleted second row number 4 smaller number 5, 1 of third or fourth row, , fifth row have smaller number 3 last row 5.
query remove duplicate in sql-server:
;with c ( select *, row_number() over(partition [key] order number desc) n youtable ) delete c n > 1
Comments
Post a Comment