• Post Reply Bookmark Topic Watch Topic
  • New Topic

Tree structure problem

 
faisal khan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello
i have the following table having
EMP BOSS SALARY
--------------- --------------- ----------
Albert NULL 1000
Bert Albert 900
Chuck Albert 900
Donna Chuck 800
Eddie Chuck 700
Fred Chuck 600
Faisal Fred 400

it create a tree structure , and i want to write select statement to get
all employees whose boss is chuck
like donna , eddie, fred and faisal too, bcs fred boss is also Chuck
please help me in solving the problem
Faisal
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36031
432
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Faisal,
You are going to need more than one query. First, you get all the employees whose direct boss is Chuck. Then, you get the employees that have a boss that was returned by your first query. Repeat until your queries don't return any results.
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!