Country
You are in the Nigeria edition. Type your country to switch.
Nigeria
Loading every country…
No country matches. Check the spelling, or choose "Any country" for the Global edition.
Your learning profile
Data skills: SQL and Python basics · Lesson 4 of 7
Joining tables: SQL JOIN for beginners
A join brings facts from two tables together using a shared key. This lesson joins the example sales table to products and regions, compares inner and left joins, shows how to find rows with no match, and explains how a bad join quietly duplicates rows and inflates totals.
This lesson is complete in writing. A video for it is on its way.
What you will learn
- By the end you can join two tables on a shared key and read the result.
- You can explain the difference between an inner join and a left join, and choose between them.
- You can find rows with no match using a left join and IS NULL.
- You can spot a join that duplicates rows, and check every join by counting rows.
Key terms in this lesson
- SQL join
- An SQL operation that combines rows from two tables by matching values in a shared column, such as a product code, so facts held separately can be used together.
- Foreign key
- A column in one table whose values point to the primary key of another table, such as a product code in a sales table that refers to a row in a products table.
- Primary key
- A column or set of columns that identifies each row in a database table uniquely, such as ticker plus date in a daily price table.
- Inner join
- A join that keeps only the rows with a match in both tables. Rows without a partner on either side are dropped from the result without any warning.
- Left join
- A join that keeps every row of the first table and fills the columns from the second table with NULL where no matching row exists.
- Join fan-out
- The unwanted multiplication of rows when a join key appears more than once on one side, which repeats rows and inflates any totals calculated afterwards.
- Step 1: Why tables need joining, not started
- Step 2: Inner join and left join, not started
- Step 3: Finding rows with no match, not started
- Step 4: Joining a third table, not started
- Step 5: When a join duplicates rows, not started
About 8 min of reading
Step 1 of 5
Why tables need joining
Opening this step…
Step 2 of 5
Inner join and left join
This step opens when you finish the one above.
Step 3 of 5
Finding rows with no match
This step opens when you finish the one above.
Step 4 of 5
Joining a third table
This step opens when you finish the one above.
Step 5 of 5
When a join duplicates rows
This step opens when you finish the one above.
Key takeaways
The key takeaways open when you finish every step.
Lesson quiz
6 questions. You need 85% to pass.
The quiz opens when you finish every step.
Stockertim Learn is education. It explains how investing works and never recommends buying or selling anything.
Popular this week: Basics: BeginnerNGX & Africa: Beginner