Reputation: 123
I have the typical emp table from which i want to fetch the hierarchical organisation chart of the employee specified.
i.e. if I Enter 101 as the EMPID in where clause then it should show:
ID NAME MGRID
101 SCOTT 104
104 TIGER 106
106 KING ---
I want to know if it can be solved with SQL or I have to use PL/SQL ? Thanks.
Upvotes: 1
Views: 731
Reputation: 5684
Assuming you are using oracle, I think Hierarchical Queries are just what you need:
http://docs.oracle.com/cd/B19306_01/server.102/b14200/queries003.htm
Upvotes: 1
Reputation:
SELECT id, name, mgrid
FROM emp
START WITH id = 101
CONNECT BY PRIOR mgrid = id
ORDER BY id
Upvotes: 2