Outer Join

In this lesson we are going to study about Outer Join in a database.

OUTER JOIN:  
      In Outer join operation ,all records from the source table are included in the result even though they did't satisfy the join condition .

TYPE OF OUTER JOIN:
  • Left outer join .
  • Right outer join .
  • Full outer join .
SYNTEX:

SELECT Columns Names from both Tables FROM tablenameA
LEFT | RIGHT | FULLOUTER JOIN tablenameB ON condition



Left outer join : 
 
  • Left outer join return the unmatched rows from the left table with matched rows from the right table.
  • It selects all the matched rows from the tableB and unmatched rows from tableA.
  • Specify the outer join operator in the left side table.




Right outer join :
 
  • Return the unmatched rows from the right tableB plus matched rows from the left tableA.
  • Specify the outer join operator in the right side table.
 Full outer join :
  • It is a combination of left and right outer join .
  • Join operation combines the results of both left and right outer join .
  • The joined table will contain all the records from both tables.
  • Fill the values NULL for missing matches on either side .
Example:

SQL :
  •  Left outer join 
          select emp.employee_id,emp.last_name,dept.department_id
          from employees emp
          left outer join departments dept
          on
          emp.department_id=dept.department_id;

  • Right outer join
       select emp.employee_id,emp.last_name,dept.department_id
        from employees emp
        right outer join departments dept
        on
        emp.department_id=dept.department_id;

  • Full outer join 
        select emp.employee_id,emp.last_name,dept.department_id
        from employees emp
        full outer join departments dept
        on
        emp.department_id=dept.department_id;



Related Article
I am interested in hearing your feedback, so that I can improve my articles and learning resources for you.connect with us on facebooktwitter

Share

Did you enjoy reading this and found it useful? If so, please share it with your friends:

No comments:

Post a Comment