/    /  MySQL – Right Join

MySQL – Right Join

 

MySQL - Right Join

By using a Right Join, two or more tables are joined, and only those rows from the other table that satisfy the join condition are returned. When there are no matches in the left-hand table, a NULL value is returned. This method is similar to the Left Join except that the results of the join tables are reversed. Alternatively, it is called a Right Outer Join. As a result, Outer is an optional clause for Right Joins.

Syntax

SELECT column_list  
FROM Table1  
RIGHT [OUTER] JOIN Table2   
ON join_condition;  

This join begins by selecting the columns from the right-hand table and matches each record in this table against the records in the left-hand table. Both records must fulfill the given join condition in order for a new row set to be returned as output. If the right-side table does not contain any rows matching the left table, it combines those rows with Null values. Right Join returns all data from the right-side table, regardless of whether it matches the rows from the left table.

Examples

SELECT employees.emp_no  ,employees.first_name
FROM employees 
RIGHT JOIN dept_emp  ON dept_emp.emp_no = employees.emp_no;

MySQL - Right Join