(a clean way to combine data where both sides match up)
👀 Let’s say you have two tables:
🧑 customers
table:
customer_id | name |
---|---|
1 | Olivia |
2 | Mason |
3 | Zoe |
🛒 orders
table:
order_id | customer_id | item |
---|---|---|
101 | 1 | Laptop |
102 | 1 | Headphones |
103 | 2 | Phone |
104 | 4 | Keyboard |
You want to know what each customer bought.
But some customers haven’t bought anything yet, and one order (id 104) doesn’t belong to any listed customer.
You only want matches from both tables.
🔧 Syntax
SELECT customers.name, orders.item
FROM customers
INNER JOIN orders
ON customers.customer_id = orders.customer_id;
This says:
“Hey SQL, give me the name and item, but ONLY when the customer_id matches in both tables.”
✅ Result
name | item |
---|---|
Olivia | Laptop |
Olivia | Headphones |
Mason | Phone |
Zoe is excluded (no orders)
Order 104 is excluded (customer_id 4 doesn’t exist in customers
)
🧠 When to Use INNER JOIN
- You only care about data that exists in both tables
- You’re analyzing purchases, enrollments, logins — stuff that’s relational and must match
🧃 Recap
INNER JOIN
only shows rows with matching keys in both tables- Perfect for showing meaningful connections — no NULLs, no extras
- Great for reports, dashboards, clean lists