If you don't alias a subquery to be the name of the table being joined, does it cause an error?

Screen Link:
https://app.dataquest.io/m/179/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)
ON cities.facts_id = facts.id 
ORDER BY 3 DESC; 

What I expected to happen:
I did not alias the subquery, but I expected the query to run without the alias.

What actually happened:

(sqlite3.OperationalError) no such column: cities.name
[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) ON cities.facts_id = facts.id  ORDER BY 3 DESC;]
(Background on this error at: http://sqlalche.me/e/13/e3q8)

I saw that in the query above my only difference with the correct answer was that I didn’t alias the subquery as the name of the cities table, i.e. the table being joined. Would it be correct to conclude that if you use a subquery to aggregate data from one table that needs to be joined, and you don’t alias that subquery, then you will get an error? If yes, can somebody articulate exactly why? I’m having trouble putting it into words to explain to myself.

Thanks!

Yes, essentially what you are asking is true: if you don’t alias the subquery, you will get an error here because your subquery is not auto-named after the table you’ve used to construct it (ie cities).

I believe (someone please correct me if I’m wrong) the table you are joining to is technically named (SELECT * FROM cities WHERE capital = 1 AND population > 10000000) and therefore you get an error when you try to select cities.name because cities is not one of your tables being joined…it is simply the table being used to construct your subquery.