How can I get the top and bottom of a hierarchy using connect by, I have a table that stores transition between ids(ID-> REPLACE_ID), I'm interested in getting the latest id starting from any id.
--drop table test_connect_by;
create table test_connect_by(ID number, REPLACE_ID NUMBER);
insert into test_connect_by values(1,2);
insert into test_connect_by values(2,3);
insert into test_connect_by values(3,4);
insert into test_connect_by values(51,52);
insert into test_connect_by values(52,53);
insert into test_connect_by values(53,54);
insert into test_connect_by values(55,55);
SELECT id,replace_id, level
FROM test_connect_by
START WITH ID in (1,51)
CONNECT BY PRIOR replace_id = id;
I'm interested in getting the transitions from 1-4 and 51-54, alternatively I can start with 2 and get 2-4. Is there anything I can group by to identify group that start with 1 and the group that start with 51 ?