Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
I have a table like;id, Subject, typeI 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