Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Denormalize hierarchy 1

Status
Not open for further replies.

LarrySteele

Programmer
May 18, 2004
318
US
I'm working on a query to denormalize hierarchy.

Given an org chart that looks like this...

[tt]
Margaret
|
+----------+-------------+
| |
Mary Robert
| |
+-------+-------+ Michael
| |
Laura Nancy
|
Ted
[/tt]

And stored in a table that might look like this:

[tt]
EMP MGR
Laura Mary
Mary Margaret
Michael Robert
Nancy Mary
Robert Margaret
Ted Nancy
[/tt]

I'm looking for a result set like this:

[tt]
EMP MGR_LVL_1 MGR_LVL_2 MGR_LVL_3
Laura Margaret Mary
Mary Margaret
Michael Margaret Robert
Nancy Margaret Mary
Robert Margaret
Ted Margaret Mary Nancy
[/tt]

While I'm really storing employee numbers, not names, the structure is the same. Basically, I'm looking to have the full management hierarchy for each employee per row.

I know this isn't rocket science, but I haven't been able to find the solution despite searching for hierarchies here, other forums, and my best friend, Google.

What's the best method for assembling this hierarchy?

Thanks in advance,
Larry

 
Hm. SYS_CONNECT_BY_PATH looks interesting.

Thanks for pointing me in the right direction.

Larry
 
I kind of sort of had that in mind. Let us know how you get on, ok? It's always good to hear how things turn out.

Regards

T
 
T,

Thanks again, you've helped make this MUCH easier that it could have been.

I was able to effectively recreate the /name/name/name syntax from the examples. Of course, my next step would be to parse the single field into any number of multiple fields. Duncan Mein had the next step for that:
Thanks again,
Larry
 
Larry,

For Tharg's fine help, be sure to thank him by clicking the link (in the lower left corner of Tharg's posting:
star.gif
Thank thargtheslayer
for this valuable post!

[santa]Mufasa
(aka Dave of Sandy, Utah, USA)
[I provide low-cost, remote Database Administration services: www.dasages.com]
“Beware of those that seek to protect you from harm or risk. The cost will be your freedoms and your liberty.”
 
[surprise]
Thanks. Must've gotten distracted by something shiny this morning.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top