Dalam lingkungan basis data, kunci asing di tingkat atas kemungkinan besar akan menjadi nol seperti:
| pid | cid |
|------*------|
| null | 2 |
| 2 | 3 |
| 3 | 4 |
| null | 6 |
| 6 | 7 |
| 7 | 8 |
Jadi saya sarankan menggunakan sesuatu seperti:
select connect_by_root(t1.cid) as startpoint,
t1.cid as rootnode
from your_table t1
where connect_by_isleaf = 1
start with t1.cid in (8, 4)
connect by prior t1.pid = t1.cid;