> For the complete documentation index, see [llms.txt](https://dailyjournal.gitbook.io/solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dailyjournal.gitbook.io/solutions/hackerrank-solutions/prepare/sql/basic-join.md).

# Basic Join

## Population Census

{% embed url="<https://www.hackerrank.com/challenges/asian-population/problem?isFullScreen=true>" %}

```sql
select sum(ct.POPULATION) from CITY ct, COUNTRY cntry
where ct.COUNTRYCODE = cntry.CODE
and cntry.CONTINENT = 'Asia';
```

## African Cities

{% embed url="<https://www.hackerrank.com/challenges/african-cities/problem?isFullScreen=true>" %}

```sql
select ct.NAME from CITY ct, COUNTRY cntry
where ct.COUNTRYCODE = cntry.CODE
and cntry.CONTINENT = 'Africa';
```

## Average Population of Each Continent

{% embed url="<https://www.hackerrank.com/challenges/average-population-of-each-continent/problem?isFullScreen=true>" %}

```sql
select COUNTRY.CONTINENT, floor(avg(CITY.POPULATION))
from CITY, COUNTRY
where CITY.COUNTRYCODE = COUNTRY.CODE
group by COUNTRY.CONTINENT;
```

## The Report

{% embed url="<https://www.hackerrank.com/challenges/the-report/problem?isFullScreen=true>" %}

```sql
SELECT 
    CASE WHEN Grades.Grade<8 THEN NULL ELSE Students.Name END,
    Grades.Grade,
    Students.Marks
FROM Students JOIN Grades 
ON Students.Marks BETWEEN Grades.Min_Mark AND Grades.Max_Mark
ORDER BY Grades.Grade DESC, Students.Name, Students.Marks
```
