Screen Link:
https://app.dataquest.io/m/463/joining-data-in-sql/7/combining-joins-with-subqueries
My Code:
SELECT cities.name AS capital_city, facts.name AS country, cities.population
FROM facts
INNER JOIN (
SELECT * FROM cities
WHERE capital = 1 AND population > 10000000
) c ON c.facts_id = facts.id
ORDER BY 3 DESC
LIMIT 10;
What I expected to happen: So I get that the LIMIT 10 wasn’t required by the question and that’s why my code is wrong, but I still expected it to run. I don’t get why it didn’t run and outputted an error.
What actually happened:
(sqlite3.OperationalError) near "FROM": syntax error
[SQL: SELECT cities.name AS capital_city, facts.name AS country, cities.population, FROM facts INNER JOIN ( SELECT * FROM cities WHERE capital = 1 AND population > 10000000 ) c ON c.facts_id = facts.id ORDER BY 3 DESC LIMIT 10;]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
TL;DR: I input code inclusive of the correct answer with an excessive LIMIT 10 that the question didn’t ask for; expected output; instead, got an error. Why?