01 / 21

Merging
Datasets

Learn how to combine tables using join operations, understand each join type, and interpret the results for real business decisions.

Business Analytics

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?

★ Complete Picture
Combine customer demographics with purchase data to analyze spending patterns.
★ Remove Redundancy
Store data efficiently in normalized tables and assemble it only when needed.
★ Better Decisions
Cross-reference marketing campaigns with sales to measure ROI accurately.

Keys and Relationships

Customers id name 1 Alice 2 Bob 3 Carol Orders cust_id amount 1 $50 2 $120 4 $75 KEY

The Four Join Types

INNER JOIN LEFT JOIN RIGHT JOIN FULL OUTER Left table (A) Right table (B) Shaded = included

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.

id name amount 1 Alice $50 2 Bob $120 Carol (id=3) dropped: no order Order cust_id=4 dropped: no customer

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).

id name amount 1 Alice $50 2 Bob $120 3 Carol NULL Carol kept from left table; amount is NULL (no order)

Right Join and Full Outer

Right Join
Keeps all rows from the right table. Left-side columns filled with NULL when no match. It is the mirror of a left join.
Full Outer Join
Keeps all rows from both tables. NULLs fill in wherever a match is missing on either side: no data is ever lost.

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

1
Identify the key column that appears in both tables (e.g., customer_id, product_sku).
2
Choose the join type based on your business question: do you need all rows from one table or only matches?
3
Specify left and right: the "left" table goes first, the "right" table is what you are joining to it.
4
Check for NULLs in the result: they reveal unmatched rows and may need filtering or default values.
5
Validate row count: an unexpected increase often signals duplicate keys (one-to-many relationships).

Example 1: Inner Join in Action

Products sku name A1 Widget B2 Gadget C3 Gizmo Sales sku qty A1 10 B2 25 D4 5 INNER JOIN on sku → Result sku name qty A1 Widget 10 B2 Gadget 25 C3 (Gizmo) dropped: no sales record D4 dropped: no product record Result: 2 rows (only matches)

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.

sku name qty A1 Widget 10 B2 Gadget 25 C3 Gizmo NULL

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.

sku name qty A1 Widget 10 B2 Gadget 25 C3 Gizmo NULL D4 NULL 5

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.

Customers 1 Alice 2 Bob Orders 1 $50 1 $30 2 $120 Inner Join 1 Alice $50 1 Alice $30 2 Bob $120 3 rows (Alice duplicated) → Alice matches 2 orders → 2 rows for Alice

Common Mistakes

✕ Wrong Key Column
Joining on columns that don't represent the same entity (e.g., joining order_id to customer_id) produces meaningless results.
✕ Ignoring Duplicates
One-to-many keys multiply rows. Forgetting this leads to inflated totals when summing or counting.
✕ Forgetting NULLs
After a left/right/full join, NULL values in calculations (averages, sums) can silently skew results if not handled.

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)?