1. Learn
  2. /
  3. Courses
  4. /
  5. Joining Data in SQL

Exercise

This is a LEFT JOIN, right?

Nice work getting to grips with the structure of joins! In this exercise, you'll explore the differences between INNER JOIN and LEFT JOIN. This will help you decide which type of join to use.

As before, you will be using the cities and countries tables.

You'll begin with an INNER JOIN with the cities table (left) and countries table (right). This helps if you are interested only in records where a country is present in both tables.

You'll then change to a LEFT JOIN. This helps if you're interested in returning all countries in the cities table, whether or not they have a match in the countries table.

Instructions 1/2

undefined XP
  • 1
    • Perform an inner join with cities AS c1 on the left and countries as c2 on the right.
    • Use code as the field to merge your tables on.
  • 2
    • Change the code to perform a LEFT JOIN instead of an INNER JOIN.
    • After executing this query, have a look at how many records the query result contains.