SQL Right Join
A right join preserves the right input rather than the left. You can usually express the same relationship as a left join by swapping the inputs. That form is useful when working with older SQLite builds.
Understand the idea
Our runnable example uses the equivalent left-join spelling so it also works in the bundled browser runtime. In engines that support RIGHT JOIN, orders RIGHT JOIN customers on the same key preserves the customer rows. Choose the direction that makes the report's main entity easiest to see rather than alternating directions inside a long query.
Where to try it
Run this example in the SQL playground. The lesson link loads the shop tables and sample rows before this query. Select Run when you are ready. Every run starts fresh, so your changes do not affect the website or a previous run.
SQLite sample data · MySQL / MariaDB sample data · See the sample tables
A worked example
SELECT c.name, o.order_id
FROM customers AS c
LEFT JOIN orders AS o ON o.customer_id = c.customer_id
ORDER BY c.customer_id, o.order_id;
Read the result
Five rows are returned because Mira has two matches and Noor has one retained row with a NULL order_id. Preserving customers does not guarantee one result row per customer.
Try one change
Rewrite the displayed query with RIGHT JOIN for a database that supports it. Keep customers on the preserved side.