Lesson 22 of 30
73%
LEFT JOIN
LEFT JOIN keeps every row from the left table.
If the right table has no match, those columns are NULL.
The left table is the one after FROM.
Students even without scores
sql
Result
| name | points |
|---|---|
| Ada | 95 |
| Ada | 88 |
| Sam | 90 |
| Lin | NULL |
4 rows
Find the orphans
Who is a student with no score yet? The joined points are NULL.
sql
Result
| name |
|---|
| Lin |
1 row
INNER vs LEFT
1
INNER: only matching pairs
2
LEFT: all left rows, match if you can
3
RIGHT: all right rows, used less often
A picture
INNER JOIN is a handshake. Both people must be there.
LEFT JOIN is a roll call of the left class. Guests from the right may sit beside them.
Tip: Put the table you refuse to lose on the left.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.