-1

I am trying to retrieve the most recent 'topic 1 value' for each detailsID for the most recent date per detailsID.

I was thinking something along the lines of:

SELECT detailsID,`Topic 1 Scores`, MAX(Date) 
FROM Information.scores 
WHERE `Topic 1 Scores` IS NOT NULL 
GROUP BY `detailsID`,`Topic 1 Scores`

Is printing;

detailsID, Topic 1 Scores, MAX(Date)

2 0 26/09/2017

2 45 26/09/2017

2 100 26/09/2017

3 30 25/09/2017

3 80 14/10/2017

Rather than actually selecting the most recent date per detailsID?

Barmar
  • 741,623
  • 53
  • 500
  • 612
Lottie T
  • 23
  • 6

1 Answers1

0

A solution like this can be found in this answer in the linked question.

SELECT t1.detailsID, t1.`Topic 1 Scores`
FROM Information.scores AS t1
JOIN (SELECT detailsID, MAX(date) AS maxDate
      FROM Information.scores
      GROUP BY detailsID) AS t2 
ON t1.detailsID = t2.detailsID AND t1.date = t2.maxDate
Barmar
  • 741,623
  • 53
  • 500
  • 612