recursive query - Org hierarchy chart [message #12212] |
Fri, 07 May 2004 11:57 |
dl j
Messages: 5 Registered: May 2004
|
Junior Member |
|
|
How can we write a SQL query to recursively loop to find who works for an employee... and who works for the subordinate employees... etc, etc i.e. create a hierarchy chart.
I would like to print the results on a webpage.
Thank you.
|
|
|
Re: recursive query - Org hierarchy chart [message #12214 is a reply to message #12212] |
Fri, 07 May 2004 13:06 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
Hierarchical query example:
sql>select level, empno, ename, job, mgr
2 from emp
3 start with mgr is null
4 connect by prior empno = mgr;
LEVEL EMPNO ENAME JOB MGR
--------- --------- ---------- --------- ---------
1 7839 KING PRESIDENT
2 7566 JONES MANAGER 7839
3 7788 SCOTT ANALYST 7566
4 7876 ADAMS CLERK 7788
3 7902 FORD ANALYST 7566
4 7369 SMITH CLERK 7902
2 7698 BLAKE MANAGER 7839
3 7499 ALLEN SALESMAN 7698
3 7521 WARD SALESMAN 7698
3 7654 MARTIN SALESMAN 7698
3 7844 TURNER SALESMAN 7698
3 7900 JAMES CLERK 7698
2 7782 CLARK MANAGER 7839
3 7934 MILLER CLERK 7782
14 rows selected.
|
|
|
|
sor - Re: recursive query - Org hierarchy chart [message #12455 is a reply to message #12214] |
Fri, 21 May 2004 08:34 |
dl j
Messages: 5 Registered: May 2004
|
Junior Member |
|
|
How can we sort the output of the recursive query that Todd answered in his reply to my earlier question?
I would like to sort employees within each level. It is not "order by level". ("within each level").
Hopefully, I was clear with the question.
Thank you very much.
|
|
|