Skip to main content
Albero Academy

INNER JOIN

Combine rows from two tables where they match on a key.

Joins & Combining10 min

Data is spread across related tables, and joins stitch it back together. An INNER JOIN — the most common — returns rows that have a match in both tables, based on a key.

Joining two tables

students + programmes
SELECT s.name, p.name AS programme
FROM students s
JOIN programmes p ON s.programme_id = p.id; -- match on the key
-- only students whose programme_id exists in programmes appear

How it works

The ON clause is the matching condition. For each pair of rows where it's true, the join produces one combined row. Table aliases (s, p) keep the column references short and unambiguous when both tables share a column name.

Key takeaways

  1. 01An INNER JOIN returns rows with a match in both tables, via the ON key.
  2. 02The ON clause is the matching condition between the tables.
  3. 03Use table aliases and qualify columns (s.name) to keep joins clear.
  4. 04JOIN and INNER JOIN are identical; chain joins for three+ tables.

Finished this chapter?

Mark it complete to track your progress through SQL.