![]() |
VOOZH | about |
In SQL, the RIGHT JOIN (also called RIGHT OUTER JOIN) is used to combine rows from two tables based on a related column. It returns all records from the right table and only the matching records from the left table. If there is no match in the left table, the result will show NULL values for the left tableβs columns.
Syntax:
SELECT column_name(s)
FROM tableA
RIGHT JOIN tableB
ON tableA.column_name = tableB.column_name;
In this example, we will consider two tables employee table containing details of the employees working in the particular department the and department table containing the details of the department
Query:
SELECT
e.emp_no,
e.emp_name,
d.d_name,
d.location
FROM employee e
RIGHT JOIN dept d
ON e.dept_no = d.dept_no;
Output: