Explain self join with an example

Showing Answers 1 - 5 of 5 Answers

waheedha

  • Jul 5th, 2006
 

self join means joing the tables to itself.for example..........supose u have a table called employees having emp_id,emp_name,manager_id.........to find the name's of the each employee's manager u need to join the employees table to itself.

For example, to find the name of

xyz's  manager, you need to:

? Find xyz in the EMPLOYEES table by looking at the EMP_NAME column.

? Find the manager number for xyz by looking at the MANAGER_ID column. xyz?s

manager number is  some 101.

? Find the name of the manager with EMP_ID 101 by looking at the EMP_NAME

column. abc?s employee number is 101, so abc is xyz?s manager.

In this process, you look in the table twice. The first time you look in the table to find xyz in the

EMP_NAME column and MANAGER_ID value of 101. The second time you look in the

EMPL_ID column to find 101 and the EMP_NAME column to find abc.

  Was this answer useful?  Yes

Lalita.p

  • Sep 18th, 2006
 

self join requires two or more tables. but the two tables are not Necessarily different tables.u can take one table and other table is the instance of the first table .and can implement self join concept on these tables.

  Was this answer useful?  Yes

bhargav

  • Nov 28th, 2006
 

          Self joints : joining a single table by itself using its instance as another table is called as self joint.

               If we want to get employee name those are belogs to same dept from emp table the fallowing self joint query can override over requirement.

     Select e.ename,d.deptno from emp e,emp d where e.deptno=d.deptno;

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions