Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2003
    Posts
    13

    Unanswered: Possible newbie SQL question. Help.

    I have the below table

    Organization:
    emp_id, emp_name, manager_id, level

    level 3 employees report to level 2 employees than report to level 1 employees

    I need to select all level 3 employees, their direct manager (level 2) and indirect manager (level1).

    Any help?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Possible newbie SQL question. Help.

    Treat each level as a separate table:

    select l3.emp_name, l2.emp_name, l1.emp_name
    from emp l1, emp l2, emp l3
    where l1.emp_id = l2.manager_id
    and l2.emp_id = l3.manager_id;

    Or in Oracle there is "CONNECT BY" to perform a tree-structured query.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •