iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

SQL INNER JOIN

INNER JOIN returns only the rows that have a match in both tables.

Example

SQL
SELECT c.name, o.total
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;

What gets dropped

RowResult
Customer with no ordersNot in the result.
Order whose customer was deletedNot in the result.
Customer with 3 ordersAppears 3 times — one per order.

Implicit comma join

You may see this older style — equivalent to INNER JOIN but harder to spot the join condition:

SQL
-- Old, avoid in new code
SELECT c.name, o.total
FROM customers c, orders o
WHERE o.customer_id = c.id;

Modern style separates filtering (WHERE) from linking (ON) so reviewers can read each independently.

JOIN = INNER JOIN

The word INNER is optional. JOIN alone means INNER JOIN in every major database.

Tip: Use INNER JOIN when "no match" should mean "drop the row". If you need customers with or without orders, switch to LEFT JOIN.

Example

Example
SELECT c.name, o.total
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;
Try it Yourself »

Exercise

Returns only matching rows from both tables.

JOIN orders ON ...

Test yourself

Q1. INNER JOIN drops rows that…
Q2. A customer with 3 orders appears in the INNER JOIN result…
Q3. INNER JOIN is equivalent to the legacy…

Discussion

Loading…