Home » SQL & PL/SQL » SQL & PL/SQL » recursive query - Org hierarchy chart
recursive query - Org hierarchy chart [message #12212] Fri, 07 May 2004 11:57 Go to next message
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 Go to previous messageGo to next message
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.
Re: recursive query - Org hierarchy chart [message #12215 is a reply to message #12214] Fri, 07 May 2004 16:06 Go to previous messageGo to next message
dl j
Messages: 5
Registered: May 2004
Junior Member
Thanks a million. I will work on this code as a base and may have to come back with questions.

Thanks again!!
sor - Re: recursive query - Org hierarchy chart [message #12455 is a reply to message #12214] Fri, 21 May 2004 08:34 Go to previous message
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.
Previous Topic: what is equivalent data type in Oracle
Next Topic: segmentation problem
Goto Forum:
  


Current Time: Fri Apr 19 08:29:55 CDT 2024