Skip to content

SQL INNER JOIN

INNER JOIN returns only the pairs of rows where the ON condition is true. Rows without a partner on the other side disappear.

pick a join type
customers
idname
1Ada
2Grace
3Linus
4Hedy
orders
idcustomer_id
1011
1022
1031
1089
customersorders
SELECT c.name, o.id, o.total
FROM customers c
INNER JOIN orders o ON o.customer_id = c.id;

Only pairs where the ON condition matches. Ada appears twice because she has two orders. Linus and Hedy (no orders) and order 108 (unknown customer 9) drop out.

Result · 3 rows
nameorder idtotal
Ada101131
Ada1039.5
Grace10234.5

Run this on the full sample database

INNER JOIN example, row by row

Only customers with orders, and only orders with a known customer, survive. Linus and Hedy (no orders) and order 108 (unknown customer 9) are dropped.

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

▶ Run it on the full sample database

What to know about INNER JOIN

  • JOIN on its own means INNER JOIN. The two are interchangeable.
  • Table order does not change the result of an INNER JOIN; it only matters for LEFT and RIGHT joins.
  • Chain joins to combine more tables: FROM orders o JOIN customers c ON … JOIN order_items i ON … JOIN products p ON ….
  • The old comma syntax (FROM a, b WHERE a.id = b.a_id) gives the same result, but forgetting the WHERE silently produces a cross join. Prefer explicit JOIN … ON.

Other join types

Syntax for everything else, from GROUP BY to window functions, is on the SQL cheat sheet.

INNER JOIN questions

What does INNER JOIN do in SQL?

It combines rows from two tables and keeps only the pairs where the ON condition is true, typically where a foreign key equals a primary key.

Is JOIN the same as INNER JOIN?

Yes. In standard SQL and in MySQL, PostgreSQL, SQL Server, Oracle and SQLite, a bare JOIN is an INNER JOIN.

What is the difference between INNER JOIN and LEFT JOIN?

INNER JOIN drops rows that have no match. LEFT JOIN keeps every row of the left table and fills the missing right-hand columns with NULL.

Is INNER JOIN faster than WHERE?

An INNER JOIN … ON and the equivalent comma join with a WHERE condition are planned the same way by modern optimizers. Choose JOIN … ON for readability and to avoid accidental cross joins.

Can an INNER JOIN return duplicate rows?

Yes. Each matching pair becomes one row, so a customer with two orders appears twice. That is correct behaviour; use GROUP BY or DISTINCT only if you really need one row per customer.