Self Join:

Joining a table to itself is called as self join. Let's see an example- to find the name of each employee's manager. Here we need to join the emp table to itself. For example to find out the manager of a particular employee what you have to do is:
Find out the employee in the emp table by looking the emp-name column.
Get the manager id of that employee by looking at the manager-id column. Let's say the id of the manager is 101. Find out the name of the employee whose employee id is 101.


To see all the employee along with there manager for whom they work the statement is:

Select worker. emp-name, manager. emp-name
From emp worker , emp manager
Where worker. manager-id =manager .employee-id ;

In the above example , the where clause specifies a condition that is where a manager id of worker table matches the employee id of the manager table .
In the above example the emp table joins to itself. To simulate two table in the from clause there are two aliases, namely worker and manager for the same table emp.


Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Phone: 0674-2361252
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved