I am trying to query a (large) Oracle 9 table that represents some hierarchical data. The Parent items have their own Id as Parent ID. As an example;
ID PARENTID
----- --------
1 1
2 1
3 2
4 2
5 3
6 6
7 6
8 6
9 4
10 10
I want to have a query that returns each ID, along with the ultimate Parent for that ID, so continuing my example
ID UlitimateParent
---- ----
1 1
2 1
3 1
4 1
5 1
6 6
7 6
8 6
9 1
10 10
I’ve seen a few examples using Connect By but can’t seem to get this to work. Any ideas ?
In 10g+, you would use the
CONNECT_BY_ROOTfunction:In 9i, you could use
SYS_CONNECT_BY_PATH(with appropriate substring):