INNER JOIN
An INNER JOIN returns only the rows that have a match in both tables. Rows with no matching partner in the other table are left out of the result.
SQL
INNER JOIN is the most common join. If you join orders to customers with an inner join, you get only orders that have a valid, existing customer — unmatched rows simply disappear from the output.
The word INNER is optional in most databases, so writing just JOIN means an INNER JOIN.
Syntax
SELECT columns
FROM table_a
INNER JOIN table_b ON table_a.key = table_b.key;Examples
SQL
SELECT users.name, orders.total
FROM users
INNER JOIN orders ON users.id = orders.user_id;Output:
name total
----- -----
Alice 50
Bob 20