Joins
M Right Outer Join
Right Outer Join
M right outer join keeps all right table rows.
Introduction to Right Outer Join
A right outer join is a type of join that returns all rows from the right table, along with the matching rows from the left table. If there is no match, the result is NULL
on the side of the left table. This join is particularly useful when you want to retain all records from the right table while also including matching records from the left table.
How Right Outer Join Works
In a right outer join, every row from the right table appears in the result set. For rows in the right table that do not have corresponding matches in the left table, the result will include NULL
values for all columns from the left table. This ensures that all data from the right table is preserved, making it useful for scenarios where the right table holds the primary data of interest.
Right Outer Join Syntax
The syntax for performing a right outer join can vary depending on the database system, but here is a general example:
Example of Right Outer Join
Consider two tables: Employees
and Departments
. We want to list all departments, along with the employees who belong to each department. If a department has no employees, it should still appear in the result set.
Analyzing the Result
The query above will return all departments, including those without employees. Here is what the result might look like:
- HR: Alice
- Engineering: Bob
- Marketing:
NULL
(no employees)
Joins
- Table Joins
- Inner Join
- Left Outer Join
- Right Outer Join
- Full Outer Join
- Previous
- Left Outer Join
- Next
- Full Outer Join