> For the complete documentation index, see [llms.txt](https://dshub.gitbook.io/ds-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dshub.gitbook.io/ds-hub/sql/sql-practice/popular-websites-for-sql-practice/hackerrank/sql-basic/african-cities.md).

# African Cities

[Question Link](https://www.hackerrank.com/challenges/african-cities/problem?isFullScreen=false)

Given the **CITY** and **COUNTRY** tables, query the names of all cities where the *CONTINENT* is *'Africa'*.&#x20;

**Note:** *CITY.CountryCode* and *COUNTRY.Code* are matching key columns.

**Input Format**

The **CITY** table is described as follows:

![](https://s3.amazonaws.com/hr-challenge-images/8137/1449729804-f21d187d0f-CITY.jpg)

The **COUNTRY** table IS described as follows:

![](https://s3.amazonaws.com/hr-challenge-images/8342/1449769013-e54ce90480-Country.jpg)

```sql
SELECT 
    c.name
FROM City c
LEFT JOIN Country cy
ON c.countrycode = cy.code
WHERE cy.continent = 'Africa'

-- or filter first
SELECT c.name
FROM city c
JOIN (SELECT code FROM country WHERE continent='Africa') cy
ON c.countrycode = cy.code
```
