I have an MS Access database containing a table of dates, ratings, and the people these ratings are associated with, for example
Date Score Name
1/6/11 5 Dave
1/6/11 10 Sarah
2/6/11 4 Dave
2/6/11 3 Graham
3/6/11 1 Dan
4/6/11 11 Dan
4/6/11 9 Graham
I would like to write a query to find who got the highest socre in every day, i.e. result:
Date Score Name
1/6/11 10 Sarah
2/6/11 4 Dave
3/6/11 1 Dan
4/6/11 11 Dan
I can think of two solutions to this problem (I am open to alternative suggestions):
1) Write a query to find the minimum score for each date, and then a second query connecting the first query with the original table. i.e:.
Query1:
SELECT Date, MAX(Score) AS MaxScore FROM ScoresTable GROUP BY Date
Query2:
SELECT ScoresTable.* FROM ScoresTable INNER JOIN Query1 ON ScoresTable.Date = Query1.Date AND ScoresTable.Score = Query1.MaxScore
[They can be combined as one request:
SELECT ScoresTable.* FROM ScoresTable INNER JOIN (SELECT Date, MAX(Score) AS MaxScore FROM ScoresTable GROUP BY Date) Query1 ON ScoresTable.Date = Query1.Date AND ScoresTable.Score = Query1.MaxScore
but I prefer to keep them separate to make it easier for other users, i.e. they can use the Access interface without knowing SQL]
2) Write one query with another simple query in the WHERE clause (this is the new method I just read about, does it have a name?), I.e.
SELECT * FROM ScoresTable WHERE Score = (SELECT MAX(Score) FROM ScoresTable AS st WHERE st.Date = ScoresTable.Date)
The latter is clearly more elegant, but seems to be slower. Which option is better? Datasets can be quite large.