Hone

Lessons · SQL · INNER JOIN

Only the matches

An inner JOIN returns rows where the ON condition matches on both sides; unmatched rows vanish.

Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.

What it is for

Most reporting joins are inner: an order always has a customer.

How to think about it

Should a missing match drop the row? Use inner when a missing match should exclude the row. If missing matches must still appear, you want LEFT JOIN.

Worked example

SELECT o.id, c.city FROM orders o
One column from each side; orders aliased o.
JOIN customers c ON c.id = o.customer_id;
An order with no customer row would not appear.

Your turn

Join reviews to films.

FROM reviews r  films f ON f.id = r.film_id

The trap

Duplicated rows after a join usually mean the ON matched more than one row on one side. Check the key is unique.

Next in SQL

Every SQL lesson on one page

Practise INNER JOIN on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.