I’m working with the InnoDB version of MySQL’s world database (available here) and am trying to fetch a list of the countries of South America and their capitals. In my mind, the query should look like this:
SELECT `Country.Name` as `CountryName`, `City.Name` as `CityName`
FROM `Country`, `City`
WHERE `Continent` = 'South America' AND `ID` = `Capital`;
But that one gives error #1054 - Unknown column 'Country.Name' in 'field list', even though the table Country does have the field Name.
Why isn’t MySQL finding the fields I want? How do I change the query to make it find them?
Let me know if I need to provide more information for you to be able to help me.
If you quote identifiers, do not surround the inner dot with backticks.
If you quote around the inner dot, it will be assumed to be inside the column name, rather than a separator between the table name and column name — you have a column named
Name, but not a column calledCountry.Name. In this case, however, it is unnecessary to quote any of the identifiers since none of them are MySQL reserved keywords.