Right Outer Join SQL

The RIGHT OUTER JOIN statement joins the values ​​from the first table
with the values ​​from the second table.

It will always return the rows from the second table, even if they don’t
meet the condition.

That is, if a row from the right table has no matching rows from the left
table, the left table column in the result set will have nulls, other
clauses you can use to do joins between tables are INNER JOIN and LEFT
JOIN.

The syntax is as follows:

SELECT * FROM table1 RIGHT JOIN table2 WHERE table1.column1 =
table2.column1

In this syntax, table1 is the left table and table2 is the right table.

Note that RIGHT JOIN and RIGHT OUTER JOIN are the same.

The OUTER keyword is optional.

Use a RIGHT JOIN operation to create a right outer join.

SQL Server RIGHT JOIN Example

We will use the sales.order_items and production.products table from the
sample database for the examples.

SELECT  Purchasing.SupplierTransactions.TransactionAmount,
Purchasing.SupplierTransactions.TransactionDate,
Purchasing.SupplierCategories.SupplierCategoryName
FROM Purchasing.Suppliers
RIGHT outer JOIN Purchasing.SupplierTransactions ON
Purchasing.Suppliers.SupplierID =
Purchasing.SupplierTransactions.SupplierID
INNER JOIN Purchasing.SupplierCategories ON
Purchasing.Suppliers.SupplierCategoryID = 2
ORDER BY NEWID()

Which yields the following result:

In this tutorial, you have learned how to use SQL Server’s RIGHT JOIN to
query data from two tables.

Leave a Reply

Your email address will not be published.