![]() |
Joins in a Database (SQL) are mostly used for combining data or the rows of two or more table records that are based on the same or common attribute. There are various types of Joins like Right Join, Left Join, Full Join, etc. Each join has its own syntax and data-returning capability. In this article, we will see the information about Right Join and Right Outer Join along with the example, also we will see their syntax and lastly, we will understand their differences with some unique parameters. Right JoinRight Join in SQL is used to return all the records from the rightmost table and the matching records from the leftmost table. In some scenarios, there may be a situation where there are no marches, then it will still include the rows from the right table but it will show the NULL values for the columns that are associated with the left table. In the context of the query, below is the syntax of the Left Join. Syntax:
Now, let’s see the example of Right Join: ExampleEmployee_Data Table
Department_Data Table
Query for Right JoinSELECT Employee_Data.employee_id, Employee_Data.employee_name, Department_Data.department_name Output:
Explanation: In the above example, Right Join includes all the rows from the right table (Department_Data) and matched them with the corresponding rows of the left table (Employee_Data). If there is no match, then the NULL value for the column is been displayed. From the above example, the ‘Linux‘ department in the Department_Data table has no associated employee in the Employee_Table, so the NULL value is been displayed. Right Outer JoinThe Right Outer Join is mostly similar to the Right Join, and both these joins are interchangeably used. The keyword used here is “Outer“, which is also optional and doesn’t have any severe impact on the result set of the query. In the context of the query, below is the syntax of the Right Outer Join. Syntax
ExampleLet’s consider the same tables used in the above Right Join Example: Query for Right Outer JoinSELECT Employee_Data.employee_id, Employee_Data.employee_name, Department_Data.department_name Output:
Explanation: In the above example, all the records from the right table (Department_Data) are preserved, and the matching records or data from the right-most table (Employee_Data) are included. If there is no match, then the NULL values are displayed for the columns of the left table. The department ‘DBMS‘ in the Department_Data table has the 2 employees (Aditi, Vaishnavi) associated with it, so their information is included in the result. The ‘Linux‘ department has no employees, so the NULL values are displayed in the resultant table. Right Join V/S Right Outer Join
FAQs: Right Join vs Right Outer JoinWhen should we use Right Join in Database?
Specify the advantages of using Right Outer Join.
What happens to non-matching records in Right Outer Join?
Can we use Right Join for updating or deleting data in the tables?
|
Reffered: https://www.geeksforgeeks.org
Databases |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 16 |