Choosing your join
Now that you're fully equipped to use joins, try a challenge problem to test your knowledge!
You will determine the names of the five countries and their respective regions with the lowest life expectancy for the year 2010. Use your knowledge about joins, filtering, sorting and limiting to create this list!
This exercise is part of the course
Joining Data in SQL
Exercise instructions
- Complete the join of
countries AS c
withpopulations as p
. - Filter on the year 2010.
- Sort your results by life expectancy in ascending order.
- Limit the result to five countries.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
c.name AS country,
region,
life_expectancy AS life_exp
FROM countries AS c
-- Join to populations (alias as p) using an appropriate join
___
ON c.code = p.country_code
-- Filter for only results in the year 2010
___
-- Sort by life_exp
___
-- Limit to five records
___;