Hierarchy again and again and again ! [message #684172] |
Wed, 14 April 2021 18:28  |
Amine
Messages: 363 Registered: March 2010
|
Senior Member |

|
|
Hi all,
I have this table :
drop table hierarchy;
create table hierarchy
(
id int ,
id_sup int
)
;
insert into hierarchy values (1,null);
insert into hierarchy values (2,1);
insert into hierarchy values (3,2);
insert into hierarchy values (4,1);
insert into hierarchy values (5,4);
insert into hierarchy values (6,1);
Then I run this query :
SQL> select
2 id
3 , id_sup
4 , connect_by_root id id_root
5 , connect_by_root id_sup id_sup_root
6 from hierarchy
7 where 1 = 1
8 connect by
9 prior id = id_sup
10 start with id_sup = 1
11 ;
ID ID_SUP ID_ROOT ID_SUP_ROOT
--------- --------- --------- -----------
2 1 2 1
3 2 2 1
4 1 4 1
5 4 4 1
6 1 6 1
SQL>
The problem is that this query does not offer this row :
ID ID_SUP ID_ROOT ID_SUP_ROOT
--------- --------- --------- -----------
1 1 1
How can I write my query to get this row added ?
Thanks in advance,
|
|
|
|
|
|