Geek Slack

My SQL Tutorial
About Lesson


MySQL RIGHT JOIN Keyword


MySQL RIGHT JOIN Keyword

The RIGHT JOIN keyword in MySQL returns all records from the right table (table2), and the matched records from the left table (table1). The result is NULL from the left side if there is no match.

Example:

SELECT customers.customer_name, orders.order_id
FROM customers
RIGHT JOIN orders ON customers.customer_id = orders.customer_id;

This query retrieves customer names along with their order IDs, including orders placed by customers who are not in the customer table.

The RIGHT JOIN keyword is useful for retrieving all records from one table along with matching records from another table, even if there are no matches.

Join the conversation