Skip to content
Joining Data in SQL
Joining Data with SQL
Here you can access every table used in the course. To access each table, you will need to specify the world
schema in your queries (e.g., world.countries
for the countries
table, and world.languages
for the languages
table).
Take Notes
Add notes about the concepts you've learned and SQL cells with queries you want to keep.
Add your notes here
DataFrameas
world_info
variable
-- Add your own queries here
SELECT *
FROM world.languages
LIMIT 5
-- Select all columns from cities
SELECT *
FROM cities;
SELECT *
FROM cities
-- Inner join to countries
INNER JOIN countries
-- Match on country codes
ON cities.country_code = countries.code;
-- Select name fields (with alias) and region
SELECT cities.name as city,countries.name as country, countries.region
FROM cities
INNER JOIN countries
ON cities.country_code = countries.code;
-- Select country and language names, aliased
SELECT c.name AS country, l.name AS language
-- From countries (aliased)
FROM countries as c
-- Join to languages (aliased)
INNER JOIN languages as l
-- Use code as the joining field with the USING keyword
USING(code);
SELECT c.name AS country, l.name AS language, official
FROM countries AS c
INNER JOIN languages AS l
-- Match using the code column
USING (code)
-- Select fields with aliases
SELECT c.code AS country_code, name, year, inflation_rate
FROM countries AS c
-- Join to economies (alias e)
INNER JOIN economies AS e
-- Match on code field using table aliases
ON c.code = e.code
-- Select fields
SELECT c.name, p.year, p.fertility_rate, e.year, e.unemployment_rate
FROM countries AS c
INNER JOIN populations AS p
ON c.code = p.country_code
-- Join to economies (as e)
INNER JOIN economies AS e
USING(code)
-- Match on country code