by Joshua Brauer on July 4, 2004
    
    
  Here's a snippet of code to get the most recent entry for a person from a list of records with dates. I use this in a situation where I have a list of GPAs for students. The list of GPAs is updated each day for a couple of weeks. The challenge is that some students graduate and are dropped from the list each day so I need to pick the most recent record for each person in the database.
SELECT name, gpa, standing, run_date
FROM  `ranking`  AS a
WHERE ( standing =  '123' OR standing =  '122' ) AND a.run_date = (
SELECT MAX( run_date )
FROM  `ranking`  AS b
WHERE b.name = a.name )
ORDER  BY standing, gpa DESC