In this article, we will learn how to use the RIGHT JOIN keyword in SQL.

The RIGHT JOIN keyword is used to select all records from the table2 (right table), and the matched records from the table1 (left table). If there is no match, the result from the left side is NULL.

Syntax

SELECT column_name(s)
FROM TABLE_NAME1
RIGHT JOIN TABLE_NAME2
ON TABLE_NAME1.column_name = TABLE_NAME2.column_name;

Example

The subsequent statement would select all technologies and any articles if they have. The RIGHT JOIN keyword returns all records from the right table (Technology), even if there are no matches in the left table (Article).

SELECT Article.*, Technology.Name
FROM Article
RIGHT JOIN Technology ON Article.TechID = Technology.ID;

 

Also, check How To Use LEFT JOIN Keyword In SQL