Top 5 records per group

  • Thread starter Thread starter Jay
  • Start date Start date
J

Jay

Hi,

I have a table (tblPrices) which contains the following fields:
Manufacturer, SoldPrice, OrderID

What I want is a query to return the 5 highest SoldPrices for each
Manufacturer. I have tried the suggested sql in Allen Browne's website but
can't get it to work.

Can anyone advise what the query (& subquery) would look like,l with the
above table and field names. I'm confident that if I can get a working
example I'll understand the principle better.

Many thanks......Jason
 
You can rank by group or, for a relatively small table, use a subquery like:

SELECT a.manufacturer, a.soldPrice, a.orderID
FROM tblPrices AS a
WHERE a.soldPrices = (SELECT TOP 5 b.soldPrices
FROM tblPrices AS b
WHERE b.manufacturer = a.manufacturer
ORDER BY soldPrices DESC)


Hoping it may help,
Vanderghast, Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Top 5 by a GROUPing? 1
Delete sub query problems 4
Limit recordset to top 1 per group 19
Selecting top 5 2
Remove Ties from a Top 5 query 10
Update Query 1
Top 2 per Group 2
Top Two Items per customer 18

Back
Top