Skip to content
Justice Tech School

NULL and Joins

NULL never equals NULL, so rows with NULL keys do not join.

Example
SELECT s.name, r.name AS referrer FROM students s LEFT JOIN students r ON r.id = s.referred_by LIMIT 3;

Result

name  | referrer
Ada   | NULL
Kofi  | Ada
Amina | Ada

Exercise

Keep unmatched.

FROM a  JOIN b ON a.x = b.x

Quiz Test

Does NULL = NULL match in a join?

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