SQLPathLab
Joins · Basic

INNER JOIN

Returns only rows that match in both joined tables.

Overview

INNER JOIN returns only row combinations that satisfy the ON condition on both sides; unmatched rows are excluded. If a join key is not unique, one row can match several rows and multiply the result. Check key uniqueness and row counts before adding aggregation or further filters.

Basic syntax

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

Examples

INNER JOIN example

Join orders to customers by customer_id and return only orders that have a matching customer.

Sample table

Table:orders
orders
idcustomer_id
1 101
2 102
3 101
4 104
Table:customers
customers
idname
101 Alice
102 Bob
103 Cindy

Run result

result
idname
1 Alice
2 Bob
3 Alice

Common issues

Which rows does INNER JOIN return?

It returns only rows that match on both sides according to the ON condition.

Why does JOIN increase row counts?

The join key may have duplicates on one or both sides, creating one-to-many or many-to-many matches.

Can ON use multiple columns?

Yes. Use AND to combine multiple join conditions.

Tags

CommonJoins

Was this explanation clear?