I have a players table and a teams table and I am trying to find the youngest player in each team. I can find the youngest player:
SELECT lname, fname, dob, position
FROM players
WHERE dob = (SELECT MAX(dob) FROM players);
When I try to include the teams table I am receiving the same data as above, which is the youngest player overall. I am very new to this so I am still trying to understand multiple row subqueries. If I order by team name, I will receive the same output. Do I need another SELECT statement for the teams table as well? How would I go about doing that if so? Changing operator from IN to ALL or ANY will also give me the same output.
SELECT lname, fname, dob, position, name
FROM players p JOIN teams t ON p.team_id = t.id
WHERE dob IN (SELECT MAX(dob) FROM players);
I am working in LiveSQL if that helps.