Mysql
 sql >> Database >  >> RDS >> Mysql

Sinistra Unisciti al record più recente

SELECT
  g.*, s.*
FROM
  GAMES g
LEFT JOIN
(
    SCORES s
  INNER 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
)
    ON s.game_id = g.id