I have a sample table that contains 3 columns: id
, parent_id
and name
Let's say that the hierarchy that is present in my table is as follows:
I
I.A
I.A.a
I.A.b
I.A.b1
I.A.b2
I.B
I.C
II
II.A
My goal is to retrieve all the ascendants of a given row. For example, for I.A.b2
, the result would be:
I
I.A
I.A.b
I.A.b2
I tried to use the following connect-by
query but with no success:
SELECT name
FROM test
where id = 7 -- 7 is the id of I.A.b2 in my example
CONNECT BY PRIOR id = parent_id
START WITH parent_id is null;
Any suggestion would be helpful