get unique sort result ids

ID SORT 2000001 1 2000054 1 2000161 1 2004102 1 2000126 8 2000161 8 2004102 8 2000001 51 2000054 51 2000161 51 2004102 51 2000126 58 2000161 58 2004102 58 Output ID SORT 2000001 1 2000054 1 2000161 1 2004102 1 2000126 8 2000161 8 2004102 8

we want all unique ID values with minimum sort values


February 2nd, 2014 2:12am

Try the below:

;With cte

as

(Select *,Row_number() over(partition by id order by SORT asc) Rn From Table)

Select * From cte

Where Rn=1

Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2014 2:38am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics