Get startedGet started for free

Subquery inside SELECT

As explored in the video, there are often multiple ways to produce the same result in SQL. You saw that subqueries can provide an alternative to joins to obtain the same result.

In this exercise, you'll go further in exploring how some queries can be written using either a join or a subquery.

In Step 1, you'll begin with a LEFT JOIN combined with a GROUP BY to select the nine countries with the most cities appearing in the cities table, along with the counts of these cities. In Step 2, you'll write a query that returns the same result as the join, but leveraging a nested query instead.

This exercise is part of the course

Joining Data in SQL

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

-- Find top nine countries with the most cities
___
-- Order by count of cities as cities_num
___
-- Limit the results
___
Edit and Run Code