Table Joins
Connecting Your Data
Learn how INNER JOIN and LEFT JOIN combine rows from multiple tables, and how to interpret the results in real business scenarios.
Why Do We Need Table Joins?
Real business databases store data across many tables rather than one giant spreadsheet. A company might have a Customers table, an Orders table, and a Products table: each focused on one subject.
To answer a question like "Which customers placed orders last month?" you need to combine rows from both the Customers and Orders tables. That combination is called a join.
The Shared Key Column
Visualizing Joins: The Venn Diagram
Think of each table as a circle. The overlap region represents rows where the shared key values exist in both tables. Different join types select different regions of this diagram.
What Is an INNER JOIN?
What Is a LEFT JOIN?
INNER vs LEFT: The Core Difference
The ON Clause: Setting the Match Rule
The ON clause specifies which columns must match between the two tables. It acts as the bridge connecting rows from left to right.
How to Write a Join Query
Example 1: INNER JOIN in Action
| customer_id | name |
|---|---|
| 101 | Alice |
| 102 | Bob |
| 103 | Carol |
| customer_id | amount |
|---|---|
| 101 | $250 |
| 102 | $180 |
| 101 | $75 |
| name | amount |
|---|---|
| Alice | $250 |
| Alice | $75 |
| Bob | $180 |
Example 2: LEFT JOIN in Action
| name | amount |
|---|---|
| Alice | $250 |
| Alice | $75 |
| Bob | $180 |
| Carol | NULL |
Example 3: Finding Inactive Customers
A marketing team wants to find customers who have never placed an order so they can send a promotional email. This is a classic LEFT JOIN + NULL filter pattern.
| name | |
|---|---|
| Carol | carol@email.com |
Why Joins Can Multiply Rows
Understanding NULL in Join Results
In a LEFT JOIN, NULL appears in the right table's columns when there is no matching row. NULL is not zero, not an empty string: it means "no data."
Common Mistakes with Joins
Summary: Join Types at a Glance
| Feature | INNER JOIN | LEFT JOIN |
|---|---|---|
| Rows returned | Only matching rows | All left + matching right |
| Unmatched left rows | Dropped | Kept (with NULLs) |
| Unmatched right rows | Dropped | Dropped |
| Result row count | Can be fewer or more rows than either table | ≥ left table |
| NULLs in result | No (from join logic) | Yes (right-side columns) |
| Best for | Active relationships | Complete inventories |
Question 1 of 5
You have a Products table with 50 rows and an Orders table with 200 rows. After an INNER JOIN on product_id, the result has 180 rows. What does this tell you?
Question 2 of 5
Which join type should you use to find all employees, including those who have not been assigned to any project?
Question 3 of 5
In a LEFT JOIN result, a row shows NULL for the right table's order_date column. What does this mean?
Question 4 of 5
A Students table has 100 rows. A Grades table has 500 rows (each student can have multiple grades). After a LEFT JOIN, how many rows will the result have at minimum?
Question 5 of 5
What happens if you write a JOIN without an ON clause?