P
PKI_Dave
I have a table of scores and I'd like to obtain the most recent record for
each person, but not everyone has an entry for a particular day. For
example, if I have three users with the following scores, entered on the
following days:
Name1 10 1/1/08
Name2 20 1/1/08
Name3 30 1/1/08
Name1 11 1/8/08
Name3 31 1/8/08
I would expect to get
Name1 11 1/8/08
Name2 20 1/1/08
Name3 31 1/8/08
I've tried several queries, but I only get the names for the most recent
date, skipping anyone without a record for 1/8/08. This is a result of the
TOP 1 clause. Without this, though, I get multiple records for each person.
What I really want is the most recent score for every person in the table.
SELECT TOP 1 Player.PlayerName, Score.PlayerID, Score.ScoreDate
FROM Score RIGHT JOIN Player ON Score.PlayerID = Player.ID
ORDER BY Score.ScoreDate DESC;
Your help would be greatly appreciated.
each person, but not everyone has an entry for a particular day. For
example, if I have three users with the following scores, entered on the
following days:
Name1 10 1/1/08
Name2 20 1/1/08
Name3 30 1/1/08
Name1 11 1/8/08
Name3 31 1/8/08
I would expect to get
Name1 11 1/8/08
Name2 20 1/1/08
Name3 31 1/8/08
I've tried several queries, but I only get the names for the most recent
date, skipping anyone without a record for 1/8/08. This is a result of the
TOP 1 clause. Without this, though, I get multiple records for each person.
What I really want is the most recent score for every person in the table.
SELECT TOP 1 Player.PlayerName, Score.PlayerID, Score.ScoreDate
FROM Score RIGHT JOIN Player ON Score.PlayerID = Player.ID
ORDER BY Score.ScoreDate DESC;
Your help would be greatly appreciated.