If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Possible newbie SQL question. Help.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-24-03, 11:07
jwdtacos jwdtacos is offline
Registered User
 
Join Date: Sep 2003
Posts: 13
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?
Reply With Quote
  #2 (permalink)  
Old 09-24-03, 11:13
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
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.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On