The right join
The right join of SQL is the type of join that returns all rows from the right table (the table “joined”) whereas only matched rows from the other table are retrieved.
As it returns all rows from the second table/ right table, the column values for left table (in the select statement) will be shown as Null.
Syntax of right join clause
The general syntax of SQL right join clause is:
Select * from table_name1
right Join table_name2 ON table_name1.common_field = table_name2.common_field
Example of using right join clause
The example uses the same scenario as we used in the left join chapter.
This example will retrieve all records from the right table (table after the join clause, which is towards right) and only matched records from the left table by using the right join type.
The SQL query with join:
select * from tbl_employee TE right join tbl_customers_orders TC ON TE.emp_id=TC.emp_id
See the graphic of all tables and right join
As you can see in above graphic, all rows are retrieved from tbl_customers_orders whereas columns for tbl_emploee are filled with Null values.
Also see – Joins in SQL
Leave A Comment?