[joke mode ON]
The RIGHT JOIN
is the LEFT JOIN
for left-handed people.
[joke mode OFF]
RIGHT JOIN
returns all records from the right table and all the matched records from the left table.
Hereâs an example of RIGHT JOIN
for users
and purchases
:
SELECT * FROM purchases p RIGHT JOIN users u ON p.user_id = u.id
To be honest, I havenât used RIGHT JOIN
a single time during the last 5 years. The only exception is the interview question âGive me all JOIN types you know.â