Self Join

Explain Self Join with the help of an example?

Questions by karimrdd

Showing Answers 1 - 12 of 12 Answers

SUNIL JUHI NEHA SINGH

  • Jun 28th, 2012
 

Self Join=It is being defined as a table joins to itself. Example as below, Imagine this Table..
E_ID E_NAME M_ID
111 SUNIL NULL
112 RAKESH 111
113 NEHA 112
114 JUHI 113
----And if someone wants to output as
E_NAME M_NAME
SUNIL NULL
RAKESH SUNIL
NEHA RAKESH
JUHI NEHA
-----
So to get this one we have to write Self Join as----
SELECT E.NAME,M.NAME
FROM EMP E
JOIN
EMP M
ON
E.M_ID=M.E_ID

----Hope you get my answer THANKS---

  Was this answer useful?  Yes

asifeqbal

  • Mar 19th, 2015
 

The Join in which a table joined itself are called Self Join.

Code
  1. SELECT M1.Name, M2.Name

  2. FROM Manager M1 JOIN Manager M2 ON M1.EmpId=M2.EmpId

  Was this answer useful?  Yes

Chaitali

  • Sep 29th, 2015
 

Self join - Joining table itself called "Self join". In Self join we need to use alias for the same table.
Example -
SELECT E.EmpID, E.Name, M.Name As Manager Name
FROM Employee E SELF JOIN Employee M
WHERE E.MgrID = M.EmpID

  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