1. Learn
  2. /
  3. Courses
  4. /
  5. Improving Query Performance in SQL Server

Exercise

Sub-query vs INNER JOIN

Often the results from a correlated sub-query can be replicated using an INNER JOIN. Depending on what your requirements are, using an INNER JOIN may be more efficient because it only makes one pass through the data whereas the correlated sub-query must execute for each row in the outer query.

You want to find out the 2017 population of the biggest city for every country in the world. You can get this information from the Earthquakes database with the Nations table as the outer query and Cities table in the sub-query.

You will first create this query as a correlated sub-query then rewrite it using an INNER JOIN.

Instructions 1/2

undefined XP
    1
    2
  • Add the 2017 population column from the Cities table.
  • Add the outer query country code column to the sub-query.
  • Add the outer query table.