|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I have been fumbling with this problem for a while now, hopefully someone will be able to help me out with this.
I am using this following data in my table, Part ID, Reference ID. The theory is that parts in the PID col work with the parts in the RID col. For example (using row 1-3 data) PID 1 works with RID 2, 3, 4, and thus PID 2 works with RID 6, 9, 10, 5, 7 and PID 5 works with PID 11, 12. So there becomes a tierd relationship between all of the parts. What I would like to accomplish is to select all of the RIDs that work in relation to any PID within 4 tiers of the orginal PID. A simple example would be that PID 2 would have the following relationships. 9,10,5,6 (direct teir 1) which in turn would relate 11,12 (via 5, teir 2), which in turn would relate 15,16 (via 11 tier 3) and 17 (via 12, tier 3), which would relate 18 (via 17, teir 4) So far I have only been able to generate a sql statement to select 1 tier at a time, when what I am looking for is a result set containing all of the RIDs within 4 tiers of the orginal PID. That, being said, I belive that I am on the wrong track and in need of a fresh look at the problem and fresh input. PID RID ---------- ---------- 1 2 1 3 1 4 2 6 2 9 2 10 2 5 3 7 3 8 5 11 5 12 11 16 11 15 12 17 13 14 17 18 I hope I have express this in some understandable context. I would appreciate any help or input that anyone can give. Thanks, Paul |
|
#2
|
||||
|
||||
|
try this:
Code:
select tier1.PID, tier1.RID
, tier2.PID, tier2.RID
, tier3.PID, tier3.RID
, tier4.PID, tier4.RID
from yourtable tier1
left outer
join yourtable tier2
on tier1.RID = tier2.PID
left outer
join yourtable tier3
on tier2.RID = tier3.PID
left outer
join yourtable tier4
on tier3.RID = tier4.PID
where tier1.PID = 2
rudy http://r937.com/ |
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > Oracle Query Question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|