Question : Access 2003 Select TOP n records per category

Hi! I've pored over several other questions on the "TOP" function and can't quite seem to find the answer I need.

I'm working with a query in MS Access 2003 and trying to select the Top 50 customers (by sales total) within each region (each region has several hundred customers).  My records are stored in a table called tblSales with the following layout:

IDRegion,
IDCustomer,
Sales2008

I've tried various configurations of GROUP BY and sub-query options, but so far can only return the Top 50 overall, whereas I need to see the Top 50 within each region.

What am I missing here? (something very simple, I'm sure)

Thanks in advance for your help!

Joel

Answer : Access 2003 Select TOP n records per category

a more general answer like below

works even if the group contains multiple columns
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
select 
IDRegion,
IDCustomer,
Sales2008
from tblSales a
where exists ( select 1 from  ( select top 50 * from tblSales b
                                 where a.IDRegion = b.IDRegion
                                 order by Sales2008 desc
                              ) BB
                where BB.IDRegion = a.IDRegion
)
order by IDRegion, Sales2008 desc
Random Solutions  
 
programming4us programming4us