African Cities in SQL | HackerRank Solution

Hello coders, today we are going to solve African Cities HackerRank Solution in SQL.

African Cities

Problem

Given the CITY and COUNTRY tables, query the names of all cities where the CONTINENT is ‘Africa’.

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

Input Format

The CITY and COUNTRY tables are described as follows:

FieldType
IDNUMBER
NAMEVARCHAR2(17)
COUNTRYCODEVARCHAR2(3)
DISTRICTVARCHAR2(20)
POPULATIONNUMBER
CITY
FieldType
CODEVARCHAR2(3)
NAMEVARCHAR2(44)
CONTINENTVARCHAR2(13)
REGIONVARCHAR2(25)
SURFACEAREANUMBER
INDEPYEARVARCHAR2(5)
POPULATIONNUMBER
LIFEEXPECTANCYVARCHAR2(4)
GNPNUMBER
GNPOLDVARCHAR2(9)
LOCALNAMEVARCHAR2(44)
GOVERNMENTFORMVARCHAR2(44)
HEADOFSTATEVARCHAR2(32)
CAPITALVARCHAR2(4)
CODE2VARCHAR2(2)
COUNTRY

Solution – African Cities in SQL

MySQL

select city.name from city, country 
where city.countrycode = country.code 
and country.continent='Africa';

Disclaimer: The above Problem (African Cities) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

1 thought on “African Cities in SQL | HackerRank Solution”

  1. VEDANG BUCHAKE

    SELECT CITY.NAME
    FROM CITY
    LEFT JOIN COUNTRY
    ON CITY.COUNTRYCODE = COUNTRY.CODE
    WHERE COUNTRY.CONTINENT=’AFRICA’;

Leave a Comment

Your email address will not be published. Required fields are marked *