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
get unique sort result ids
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
- Proposed as answer by Uri DimantMVP, Editor 3 hours 32 minutes ago
- Marked as answer by Narendra Mangala 1 hour 47 minutes ago
Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2014 2:38am