Need to find the 2 highest numbers for each person?

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

Guest

I need to find the 2 highest numbers for each person in a table.

Is there a simple way to write a query to do this?

Eg.
person score
#1 10
#1 9
#1 8

So it would pull
#1 10 and 9 for scores
 
You can use the Top predicate. The query designer is a little inflexible with
this, so you'll need to edit the SQL view. It should look something like this:

SELECT TOP 2 Person, Score FROM MyTable Order By Score;

The TOP keyword will work against the column that the query is sorted by.
You can get more details about this in Access help.

Barry
 
This works for just one person:
SELECT TOP 2 Table1.person, Table1.score
FROM Table1
ORDER BY Table1.score DESC;

I don't know how to get it to work with multiple people
 
Sorry. I didn't catch that. You'll need a subquery. Something like this:

SELECT Score, Person FROM Table1 WHERE table1.Score IN(SELECT TOP 2 t.Score
FROM Table1 AS t WHERE t.Person = Table1.Person ORDER BY Score) GROUP BY
Person, Score;

Barry
 
Its pulling 2 scores for each person which is good. But it is not pulling
the 2 highest.

SELECT Table1.score, Table1.person
FROM Table1
WHERE (((Table1.score) In (SELECT TOP 2 t.Score
FROM Table1 AS t WHERE t.Person = Table1.Person ORDER BY Score)))
GROUP BY Table1.score, Table1.person;
 

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

Excel Excel conundrum - I've tried and tried, but 10
Query or report 5
Select & Max Function Q 3
Need help on scoring 1
Simple Formula Question 0
Highest value on report 4
Grouping based on minimums 3
Field Values in Order 2

Back
Top