Wednesday, November 27

Outer Joins- Right Outer Join / Right Join


The RIGHT JOIN keyword returns all rows from the right table (table2), with the matching
rows in the left table (table1). The result is NULL in the left side when there is no match.

Syntax-RIGHT JOIN 
  SELECT column_name(s)
  FROM table1
  RIGHT OUTER JOIN table2
  ON table1.column_name=table2.column_name;

Eg: Using AdventureWorksDW2008R2 Database

  select d.AccountKey,f.Financekey,d.AccountDescription, f.amount from DimAccount d
  RIGHT OUTER JOIN
  FactFinance f on d.AccountKey=f.AccountKey order by AccountKey asc;

Output:
when no match is found from left table DimAccount  for the corresponding rows of
the right table FactFinance, NULL result set will be displayed. In this case no nulls.