SQL Server > Joins

Right join / Right outer join in SQL Server

How to perform right join (or right outer join) in SQL Server?

Right outer join (or right join) is used to join more than one table where we want all records from the right table (the table that comes last in the query) and only matching records from left table (table name that comes first in the query).

To demonstrate this example, we have two tables as shown below



Now run the following SQL statement in the query window.

   SELECT pd.PersonalDetailsId, pd.FirstName, pd.LastName, pd.Age,
     FROM PersonalDetails pd
     Accounts ac
     pd.PersonalDetailsId = ac.PersonalDetailsId

Here, instead of LEFT JOIN, we have used RIGHT JOIN that changes the result based on right side table data. So it will give all records from Accounts table and only matching records from the PersonalDetails table.

 Views: 1477 | Post Order: 37

Write for us