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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 TOP clause

Author  Topic 

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2002-10-04 : 17:09:37
I have a table like;
id, Subject, type

I have 5 different type, so i would like to retrieve top 5 subject for each type,and order by id. (so will return 25 records). how can i do that? thanks in advance...



Edited by - saglamtimur on 10/04/2002 20:20:41

r937
Posting Yak Master

112 Posts

Posted - 2002-10-05 : 17:00:17
select type, id, subject
from yourtable X
where id in
(select top 5 id
from yourtable
where type = X.type
order by id desc)
order by type, id desc


rudy
Go to Top of Page

saglamtimur
Yak Posting Veteran

91 Posts

Posted - 2002-10-05 : 17:13:55
thanks alot

Go to Top of Page
   

- Advertisement -