I'm trying to select the youngest australian person in an event where the person.age and countryname are in different tables.
Here is my solution. But it returned to an empty rowenter image description here
SELECT AthleteName, Age
FROM Athletes
JOIN Countries ON Countries.CountryID = Athletes.CountryID
WHERE CountryName = 'Australia'
AND Age = (SELECT MIN(Age) FROM Athletes)
I believe that your issue is that the subquery (SELECT MIN(Age) FROM Athletes)
will always return the minimum age among all athletes, regardless of their country. The query below should function correctly.
SELECT AthleteName, Age
FROM Athletes
JOIN Countries ON Countries.CountryID = Athletes.CountryID
WHERE CountryName = 'Australia'
AND Age = (SELECT MIN(Age) FROM Athletes WHERE CountryID = Countries.CountryID);