1.

What is self join, explain with example?

Answer»

Self-join is the one in which the same table is joined by itself to GET the desired output. We can understand self join in case of the below SCENARIO :

Let's assume we have  below table structure for Employee :

  1. EmpId- The key identifier for Employee
  2. MgrID-The key identifier for MANAGER.which is mapped to EmpID
  3. empname-The Employee name

If we need to extract employee and manager information from the above table then the only option we have is to using self join. We can make a self join on the Employee table on JOINING ManagerID with EmployeeID. Please find below query which explains self join clearly :

ALTHOUGH we can have other alternatives as well to get the same desired result set. It uses left outer Join:



Discussion

No Comment Found