Hello everyone,
I am hopping someone can help me sort out a query.
I have two tables, one table is a players table, and a second table is a player_vitals data that stores heights and weight changes. I want to list all the players showing the latest height and weight change.
this query will not fetch the latest height and weight
SELECT a.player_id, a.player_first_name,a.player_last_name, b.player_height, b.player_weight
FROM players a
LEFT JOIN (SELECT vital_id, player_id, player_height, player_weight FROM player_vitals ORDER BY vital_id DESC LIMIT 1) b ON b.player_id = a.player_id
LEFT JOIN teams c using (team_id)
ORDER BY player_last_name, player_first_name
this query will work only if i tell it what player_id to select from
SELECT a.player_id, a.player_first_name,a.player_last_name, b.player_height, b.player_weight
FROM players a
LEFT JOIN (SELECT vital_id, player_id, player_height, player_weight FROM player_vitals WHERE player_id = 6 ORDER BY vital_id DESC LIMIT 1) b ON b.player_id = a.player_id
LEFT JOIN teams c using (team_id)
where a.player_id = 6
ORDER BY player_last_name, player_first_name
but i need I need to get my first query to work listing all players, am i missing something?
Thanks