Chaining FULL JOINs
As you have seen in the previous chapter on INNER JOIN
, it is possible to chain joins in SQL, such as when looking to connect data from more than two tables.
Suppose you are doing some research on Melanesia and Micronesia, and are interested in pulling information about languages and currencies into the data we see for these regions in the countries
table. Since languages and currencies exist in separate tables, this will require two consecutive full joins involving the countries
, languages
and currencies
tables.
This is a part of the course
“Joining Data in SQL”
Exercise instructions
- Complete the
FULL JOIN
withcountries as c1
on the left andlanguages as l
on the right, usingcode
to perform this join. - Next, chain this join with another
FULL JOIN
, placingcurrencies
on the right, joining oncode
again.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
c1.name AS country,
region,
l.name AS language,
basic_unit,
frac_unit
FROM countries as c1
-- Full join with languages (alias as l)
___
-- Full join with currencies (alias as c2)
___
WHERE region LIKE 'M%esia';