What is a self-join and when can it be used

Questions by bbkcdb

Showing Answers 1 - 12 of 12 Answers

ora.nachs

  • Mar 14th, 2007
 

Self Join is nothing but a table joining with itself.

If the data present inside the same table we need to take a alias of same table.

for ex:
empno   ename   mgr
   1             a        
   2             b          1

here, for the employee 2 , employee 1 is the manager.
To fetch the employee name and his manager name we need to join the table to itself.

  Was this answer useful?  Yes

Guest

  • Mar 27th, 2007
 

Self Join is nothing but a table joining with itself.

It is very helpful to fetching duplicate data from a table..
if we want to fetch the emp_id from emp whice are duplicate in emp tab.
examp:

select a.emp_id ,b.emp_id
    from emp a,emp b
where a.emp_id=b.emp_id and
            a.rowid<>b.rowid.

we can get duplicate value easily by help of self join.
Try it...........

  Was this answer useful?  Yes

Join the table to itself is called self join. It is used when you need to join the data with the same table data.

Ex:- SELECT A.ENAME,A.SAL ,B.ENAME,B.SAL
       FROM EMP A,EMP B

      WHERE A.MGR = B.EMPNO

  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