Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is 'Africa'.
CITY.CountryCode and COUNTRY.Code are matching key columns.
The solution is
SELECT city.NAME FROM city INNER JOIN country ON city.CountryCode = country.Code WHERE country.continent = 'Africa';
Why was city.Name
was written instead of NAME
and also why was the ınner joın was executed by ON city.CountryCode = country.Code
?
Why is use of ON city.POPULATION = country.POPULATION
and ON city.NAME = country.NAME
not working?
City
:
+-------------+----------+
| Field | Type |
+-------------+----------+
| ID | int(11) |
| Name | char(35) |
| CountryCode | char(3) |
| District | char(20) |
| Population | int(11) |
COUNTRY
:
+----------------+-------------+
| Field | Type |
+----------------+-------------+
| Code | char(3) |
| Name | char(52) |
| Continent | char(50) |
| Region | char(26) |
| SurfaceArea | float(10,2) |
| IndepYear | smallint(6) |
| Population | int(11) |
| LifeExpectancy | float(3,1) |
| GNP | float(10,2) |
| GNPOld | float(10,2) |
| LocalName | char(45) |
| GovernmentForm | char(45) |
| HeadOfState | char(60) |
| Capital | int(11) |
| Code2 | char(2) |
+----------------+-------------+