skip to Main Content

How to List the largerst city population for each country
— Use country column (not country_code), order the results by the decreasing largerst city population.

enter image description here

2

Answers


  1. SELECT MAX(population) largerst, city
    FROM <tablename>
    GROUP BY country
    ORDER BY largerst DESC, city;
    
    Login or Signup to reply.
  2. If you have to claim the largest city name for each country also, you can use this:

    SELECT l.country, r.city, l.largest
    FROM (
    SELECT country, MAX(population) AS largest
    FROM <tablename>
    GROUP BY country
    ) AS l
    INNER JOIN <tablename> AS r ON l.country = r.country AND l.largest = r.population
    ORDER BY largest DESC
    ;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search