Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 Other Topics
 Need a clarification in subquery

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2005-03-14 : 08:30:29
Ravi writes "Hi All,

I am new to this group. Now, lets get into the point.

I am having a table which stores the employee details along with their superior code. (Same like emp table in Demo database of Oracle).

I will write subquery to fetch the subordinates for the selected employee. Thats fine

Now my point is for the above said query it will fetch only his/her subordinates, whereas what i need is even the subordinate's subordinates to be displayed.

Let me make it easy with an example.

empno empname mgrcode
1 a 0
2 b 1
3 c 2
4 d 2
5 e 3
6 f 4

For the normal subquery for the above table would return only 2nd record for the manager A.

whereas i need all the record as they all are subordinate for A.

This is to display the organization hierarchy."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2005-03-14 : 08:32:21
Hi. We're established SQL Teamer's. Now let's get to the point.

When you post a question on Ask SQL Team, it says very clearly in the first item that we're a Microsoft SQL Server site, and that we don't answer Oracle questions.
Go to Top of Page
   

- Advertisement -