Merging
Datasets
Learn how to combine tables using join operations, understand each join type, and interpret the results for real business decisions.
What Is Merging?
In business analytics, data often lives in separate tables. A customer table might hold names and emails, while an orders table stores purchase history. Merging (also called joining) is the process of combining two or more tables into one based on a shared column: a key.
Why Merge Data?
Keys and Relationships
The Four Join Types
Inner Join: Only Matches
An inner join returns only rows where the key exists in both tables. If a customer has no orders, or an order has no matching customer, those rows are dropped.
Left Join: Keep All Left Rows
A left join keeps every row from the left table. If no match exists in the right table, the right-side columns are filled with NULL (blank).
Right Join and Full Outer
Inner vs. Left: Key Distinction
| Inner Join | Left Join | |
|---|---|---|
| Unmatched left rows | Dropped | Kept (NULL) |
| Unmatched right rows | Dropped | Dropped |
| Result size | Smallest or equal | At least as many as left table |
| NULLs introduced? | No | Yes (right-side columns) |
| Typical use | Confirmed matches only | Keep all from primary table |
How to Apply a Join
Example 1: Inner Join in Action
Example 2: Left Join with NULLs
A retail company wants to see all products and their sales: including products that have never sold. They use a left join with Products as the left table.
Example 3: Full Outer Join
Now the company wants a complete audit: every product and every sale, even if one side has no match. This requires a full outer join.
One-to-Many Relationships
When one key value in the left table matches multiple rows in the right table, the join creates duplicate left rows. This is normal but can inflate your result set.
Common Mistakes
Join Types Summary
| Join Type | Keeps from Left | Keeps from Right | NULLs? |
|---|---|---|---|
| Inner | Only matched | Only matched | No |
| Left | All rows | Only matched | Right side |
| Right | Only matched | All rows | Left side |
| Full Outer | All rows | All rows | Both sides |
Question 1 of 5
Table A has 100 rows and Table B has 80 rows. After an inner join, the result has 60 rows. What does this tell you?
Question 2 of 5
You want to find all employees, including those not yet assigned to a department. Employees is your primary table, Departments is secondary. Which join should you use?
Question 3 of 5
After a left join, you notice NULL values in the "price" column from the right table. What do these NULLs indicate?
Question 4 of 5
Customer table has 50 rows. Orders table has 200 rows (customers can place multiple orders). An inner join on customer_id produces 200 rows. Why?
Question 5 of 5
Which join type never produces NULL values in the result (assuming neither source table has NULLs)?