🔁 INNER JOIN – Show Only Matching Rows from Both Tables

(a clean way to combine data where both sides match up)

👀 Let’s say you have two tables:

🧑 customers table:

customer_idname
1Olivia
2Mason
3Zoe

🛒 orders table:

order_idcustomer_iditem
1011Laptop
1021Headphones
1032Phone
1044Keyboard

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

nameitem
OliviaLaptop
OliviaHeadphones
MasonPhone

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

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top