Search code examples
sql

sqlzoo: SELECT from WORLD: Matching name and capital


I'm working my way through SQLZoo, and have gotten rather stuck on the 'Matching Name and Capital' exercise. The idea is to list from the 'world' database countries that have the same first letter as their (country) name and capital, but excluding the countries where the capital is the same word as the country. I got to:

SELECT name, capital
FROM world
WHERE LEFT(name,1)=LEFT(capital,1), name <> capital

That even corresponds to what's on the answers page, but leaves me with an error message on the last part of the code (name <> capital). What's the catch?


Solution

  • You should use and in your condition instead of ,

    WHERE LEFT(name,1)=LEFT(capital,1) and name <> capital