I have a table Relatives as below
| Name | Id | Rel_Id |
--------------------------
| A | 1 | 2 |
| B | 1 | 3 |
| C | 1 | 4 |
| D | 5 | 1 |
| E | 6 | 1 |
| F | 7 | 2 |
| G | 2 | 8 |
| H | 9 | 8 |
| I | 10 | 11 |
I am looking to fetch all relatives of 1 and then recursively their relatives present in either Id column or Rel_id column. So for id OR rel_id = 1, I intend to pull A, B, C, D, E, F, G, H but not I.
I tried using oracle hierarchy sql in oracle 12c.
select
dd.*
from relatives dd
start with id = 1
connect by id = prior rel_ID
union
select
dd.*
from relatives dd
start with rel_ID = 1
connect by Id = prior rel_ID;
It is not pulling the subsequent relative Ids (F or H).
SELECTstatement twice. One of them should haveconnect by rel_id = prior id.J 5 20? 5 is related to 1, and 5 is also related to 20, but you wouldn't find 20 even in the corrected query. Is that what you do, in fact, need? That is a much harder question than you think.