INNER JOIN — Matching Rows Across Tables
10 min read
INNER JOIN
An INNER JOIN combines rows from two tables where the join condition is satisfied. Rows that have no matching row in the other table are excluded from the result. This is the most common type of join.
sql
-- List each enrolment alongside the student's name
SELECT s.name, e.enrolled_at, e.score
FROM enrolments e
INNER JOIN students s ON e.student_id = s.id;
-- Add the course title too
SELECT s.name AS student, c.title AS course, e.score
FROM enrolments e
INNER JOIN students s ON e.student_id = s.id
INNER JOIN courses c ON e.course_id = c.id
ORDER BY s.name, c.title;Table aliases (e, s, c) are essential when joining multiple tables. They keep queries concise and disambiguate columns that share the same name across tables (like id).
The keyword JOIN on its own means INNER JOIN. Writing INNER JOIN is more explicit and recommended for clarity, especially in team settings or when mixing different join types in one query.
Ready to test yourself?
Practice SQL— quiz & coding exercises