Self Join

In this lesson we are going to study about Self joins in a database.

Self Join: 
  • In order to join a table to itself we use the self join.
  • This type of join is used to compare values between two columns in the same table .

Example:-To find the name of Abhishek and Aritra manager we need to


  1. find in EMPLOYEE table by looking the Emp_name columns.
  2. find the manager number from Manager_id.
  3. find the name of manager with manager_id.








sql query :-


select
      emp.Emp_Name as Employee_name,
      manager.Emp_Name as manager_name
from  employees emp,
      employees manager
where emp.manager_id=manager.emp_id



OUTPUT: 


In simulate two table in the from clause there are two  aliases ,namely emp and manager for the same table ,EMPLOYEE.



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: