... or "How to solve the same problem in 10 different ways".
One of the common problems to solve in SQL is "Get row with the group-wise maximum". Getting just the maximum for the group is simple, getting the full row which is belonging to the maximum is the interesting step.
SELECT MAX(population), continent FROM Country GROUP BY continent; +-----------------+---------------+ | MAX(population) | continent | +-----------------+---------------+ | 1277558000 | Asia | | 146934000 | Europe | | 278357000 | North America | | 111506000 | Africa | | 18886000 | Oceania | | 0 | Antarctica | | 170115000 | South America | +-----------------+---------------+
We use the 'world' database from the MySQL manual for the examples.
The next step is to find the countries which have the population and the continent of our gathered data.
SELECT …[Read more]