Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select distinct valus

Author  Topic 

mavericky
Posting Yak Master

117 Posts

Posted - 2012-03-01 : 19:25:28
Hi,
below is the data I have in table Sample. As you can see for TRF_UODID there are many 107726 records(there is more data which has multiple rows for a single TRF_UODID - not shown below). I want to select data such that only the top 1077726 row should be seen. Similarly, in my whole data, I would like to select only unique TRF_UODID values and only the first one out of the whole list.

TRF_UODID TRF_LABEL POINT_OF_SERVICE
1077724 JA-B-950171 295840
1077726 JA-941508 295150
1077726 JA-941508 295870
1077726 JA-941508 295882
1077726 JA-941508 295893
1077726 JA-941508 295928
1077726 JA-941508 295936
1077726 JA-941508 295944
1077726 JA-941508 295957
1077726 JA-941508 295970
1077726 JA-941508 295988
1077726 JA-941508 296008
1077726 JA-941508 296013
1077726 JA-941508 296035
1077726 JA-941508 296053
Thanks,
Mavericky

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-01 : 19:37:38
something like this

select *
from
(
select rn = row_number() over (partition by TRF_UODID order by somecol), *
from yourtable
) t
where t.rn = 1



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

mavericky
Posting Yak Master

117 Posts

Posted - 2012-03-01 : 19:53:00
Thanks khtan!!!
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-01 : 20:40:47
welcome


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -