RIGHT JOIN keeps every row from the second table
RIGHT JOIN is LEFT JOIN facing the other way. It keeps every row from the table named second and fills the first table’s columns with NULL when there is no match. So an order with no known customer still shows up, with a blank name. Most people swap the two tables and write a LEFT JOIN instead, because reading left to right is easier — both give the same rows.
A tiny example
In plain English: Show me every order’s total with its customer’s name, keeping orders that have no customer.
SELECT c.name, o.total
FROM customers c
RIGHT JOIN orders o
ON o.customer_id = c.id;What comes back
| name | total |
|---|---|
| Amara | 8.5 |
| Theo | 12 |
| NULL | 6 |
The 6.00 order matched no customer, so it kept its row and the name came back NULL.
Related SQL lessons
Ready for a break?
Take on today's cozy puzzle. A fresh, bite-sized query waits every morning — no timers, no pressure.
play today's sip