The RIGHT JOIN (aka RIGHT OUTER JOIN) returns all records from the right table and the matching records from the left table. When there is no match, columns from the left table are NULL.
NULL.
// Syntax for RIGHT JOIN: keep all rows from table2 (right table)
SELECT columns
FROM table1
RIGHT JOIN table2
ON table1.common_column = table2.common_column;
// Get all customers and their orders;
include orders even if customer info is missing
SELECT customers.customer_name, orders.order_id
FROM customers
RIGHT JOIN orders
ON customers.customer_id = orders.customer_id;
// Get all products and their quantities from orders;
include products that may have no orders
SELECT products.product_name, orders.quantity
FROM products
RIGHT JOIN orders
ON products.product_id = orders.product_id;
orders has rows with no matching customers.customer_id, those rows still appear; customer_name will be NULL.INNER JOIN instead.LEFT JOIN when your mental model considers the left table primary — you can swap tables instead of using RIGHT JOIN.COALESCE() to replace NULL values in the result with a default.RIGHT JOIN to get all products and their order quantities; handle NULL with COALESCE().