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).
Note: When using sample integrations such as those that contain course data, you have read-only access. You can run queries, but cannot make any changes such as adding, deleting, or modifying the data (e.g., creating tables, views, etc.).
Inner joins combine records from two tables whenever there are matching values in a field common to both tables.
LEFT JOIN and RIGHT JOIN can be written as LEFT/RIGHT OUTER JOIN in SQL - A LEFT JOIN will return all records in the left_table, and those records in the right_table that match on the joining field provided. LEFT JOIN is more common since its typically written from left to right.
Take Notes
Add notes about the concepts you've learned and SQL cells with queries you want to keep.
the UNION operator takes two tables as input, and returns all records from both tables.
The diagram shows two tables: left and right, and performing a UNION returns all records in each table. If two records are identical, UNION only returns them once. To illustrate this, the first two records of the right table have been faded out.
UNION ALL will include duplicate records. Therefore, performing UNION ALL on this data will return nine records, whereas UNION only returned seven. No records have been faded out.
For a record to be returned, INTERSECT requires all fields to match, since in set operations we do not specify any fields to match on.
In INNER JOIN, similar to INTERSECT, only results where both fields match are returned. INNER JOIN will return duplicate values, whereas INTERSECT will only return common records once. As we know from earlier lessons, INNER JOIN will add more columns to the result set.
EXCEPT allows us to identify the records that are present in one table, but not the other. More specifically, it retains only records from the left table that are not present in the right table.
Add your notes here
-- Add your own queries here
SELECT *
FROM world.languages
LIMIT 5