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
 Single record from multiple ID'S.

Author  Topic 

hspatil31
Posting Yak Master

182 Posts

Posted - 2011-12-18 : 21:56:15
Dear All,

I have following query, So I am getting output top 1 subject whose EMPID is 100(With empid there is multiple records that's why IO have given TOP 1 in select statement). But I want If I will not give the where condition only one subject should shows for every EMPID. Anyone one record from multiple records with specific EMPID.

Can anybody please tell me how to do this ?

Query:
SELECT TOP 1 SUBJECT FROM EMPLOYEE WHERE EMPID = '100'

Thanks and Regard's
Harish Patil

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-12-18 : 22:11:50
[code]
select *
from
(
select *, row_no = row_number() over (partition by EMPID order by SUBJECT)
from EMPLOYEE
)t
where t.row_no = 1
[/code]


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

Go to Top of Page
   

- Advertisement -