title: How to return "most populated","least populated" countries grouped by continent organized in a single table via SQL?
body: <p>This is a variant of the SQLzoo tutorial.</p>
  <p>'world' table contains fields</p>
  <ol>
  <li>'population'(assigned to each country),</li>
  <li>'name' (all countries) and</li>
  <li>'continent' (assigned to each country).</li>
  </ol>
  <p>Expected output is a table as shown below</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Continent</th>
  <th>Most_populous</th>
  <th>Least_populous</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Africa</td>
  <td>Ghana</td>
  <td>xyz</td>
  </tr>
  <tr>
  <td>Asia</td>
  <td>China</td>
  <td>abc</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>I did try a complicated function as below, but was not able to get it to work due to &quot;SQL error&quot;. Not sure why.</p>
  <pre><code>SELECT DISTINCT continent
     , (SELECT x.name
        FROM world x 
        WHERE x.population = (SELECT max(y.population) 
                              FROM world y 
                              WHERE x.continent = y.continent)) AS most_populous
     , (SELECT z.name
        FROM world z
        WHERE z.population = (SELECT min(a.population)
                              FROM world a
                              WHERE a.continent=z.continent)) AS least_populous FROM world;     
  </code></pre>
  <p>Is there an easier way to get the required output?</p>