I am trying to get the largest population of any city in each country in a query. I need to join the city and country tables, as they are located on two tables, and join them through the country code.
I have the following query:
SELECT country.name AS country,
city.name AS city,
Max(city.population) AS max_pop
FROM country
INNER JOIN city
ON( country.country_code = city.country_code )
GROUP BY country.name,
city.name
ORDER BY country.name ASC;
My thought process was to get my country name, city name, and max from the joined table. I assumed and have tested, that max will give me only one result, however in this case its giving me several! I have both city and country name in my group by in order to get it to run.
Thoughts?