Left Join to most recent record
12:12 08 Aug 2012

I have two tables

Games and Scores:

games has a primary key ID

Scores has game_id which references games.id and created on among other fields.

i am attempting to adapt the second example in the accepted answer of this question to fit my needs.

  SELECT g.*,
       s.*
  FROM GAMES g
  LEFT JOIN SCORES s ON s.game_id = g.id
  JOIN (SELECT n.game_id,
               MAX(n.created_on) AS max_score_date
          FROM SCORES n
      GROUP BY n.game_id) y ON y.game_id = s.game_id
                           AND y.max_score_date = s.created_on

it almost works, it gets the most recent entry in the score table for each game. however it only returns games which have a corresponding entry in the score table. and i need it to return all games in the table reguardless of if they have a entry in the score table. which from reading the previously cited question i assumed that the left join would accomplish.

mysql sql