INNER JOIN

Basic SQL
≈ 1 min read

INNER JOIN keeps only matching rows

INNER JOIN returns only row combinations for which the ON condition is satisfied. If a row from one table has no matching row in the other table, it is excluded from the result.

SELECT o.id, u.name
FROM orders AS o
INNER JOIN users AS u ON u.id = o.user_id;

If an order refers to an existing user, the rows are combined. If no match exists, that order does not appear in the result of this join.

JOIN usually means INNER JOIN

In many queries, the word INNER is omitted: JOIN users ... is normally equivalent to INNER JOIN users ....

INNER JOIN answers the question “where is there a match on both sides?” If rows without a match must be preserved, you need an outer join, which we will cover next.