Tsallaka zuwa abun ciki
Justice Tech School

INNER JOIN

A JOIN combines rows from two tables using a condition after ON, usually matching a foreign key to a primary key. INNER JOIN (or just JOIN) keeps only the rows that have a match on both sides.

Example
SELECT students.name, courses.title
FROM enrolments
INNER JOIN students ON students.id = enrolments.student_id
INNER JOIN courses ON courses.id = enrolments.course_id
ORDER BY students.name, courses.title;

Result

name   | title
Ada    | Intro to HTML
Ada    | JavaScript
Amina  | Python
Amina  | SQL
Kofi   | Python
Tunde  | Intro to HTML
Zainab | CSS Basics
Zainab | Python

Exercise

Add the join condition keyword.

SELECT * FROM a JOIN b  a.id = b.a_id;

Quiz Test

What does INNER JOIN keep?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.