World Populations SQL Practice II question

Link to exercise:
Hi everyone!

I’m doing an SQL practice. I was asked:

What was the total population of the continent of Oceania in 2005?

So I wrote:

SELECT SUM(population)

FROM population_years

JOIN countries

ON =

WHERE continent = 'Oceania'

AND year = 2005;

and got: 52.81393

The answer from codecademy is:

SELECT SUM(population) FROM population_years

INNER JOIN countries ON = population_years.country_id

WHERE year = 2005

AND continent = 'Oceania';

and the outcome: 32.66417

I have compared them many times and still can’t find what I did that affects the code. Can someone help me please?:slight_smile:

1 Like

You’re using and the Codecademy solution is using population_years.country_id. :wink:
To see the difference try:

SELECT id, country_id FROM population_years;

Happy coding!

1 Like

What does this line of code do? = population_years.country_id

Thanks so much for posting this. I too, made this mistake.

1 Like

The JOIN is matching the two tables on the appropriate id.
The Primary Key on the countries table is id, the foreign key on population_years matches that on country_id