MAX records

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a query which has the fields category, subcategory and description.
There are multiple exceptions per category, subcategory and description. I
want to pull out the top 3 descriptions per Category and Subcategory. How do
I do this?
 
Try something like

SELECT M1.category, M1.subcategory , M1.description
FROM TableName AS M1
WHERE M1.subcategory In (SELECT Top 3 M2.subcategory
FROM TableName as M2
WHERE M2.category =M1.category
ORDER BY M2.subcategory Desc)

Assuming that the subcategory field indicate the order the records were
inserted.
If not, then change the order by to include the field name that indicate the
order of thes records
 

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

Back
Top