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)
 How to get first 10 records for each ID in group

Author  Topic 

rity
Starting Member

4 Posts

Posted - 2005-10-20 : 07:59:54
select ID, count(*) as number_of_records from table1 group by ID having count(*) > 10 order by number_of_records desc


ID number_of_records
------------ -----------------
0001 164
0002 135
0003 131
0004 70


I have table (table1) width two columns.
I have 164 records for value 0001 in colummn ID,
135 records for value 0002 in colummn ID, ...

Now I have to get first 10 records for each ID.
10 records for ID = 0001,
10 records for ID = 0002,
10 records for ID = 0003,...

Is it possible to make select statement to get these records in one Grid?

karuna
Aged Yak Warrior

582 Posts

Posted - 2005-10-20 : 08:07:58
Check this

Select Top 10 From Table1 where id = 0001

Thanks

Karunakaran
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-10-20 : 08:12:30
quote:
Originally posted by karuna

Check this

Select Top 10 From Table1 where id = 0001

Thanks

Karunakaran


Thats not the solution

Refer point 2
http://weblogs.sqlteam.com/mladenp/archive/2005/08/01/7421.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -