Исходные данныеwith t as(
select 1 as chld_id, null as prnt_id, '1_name' as nm from dual union all
select 3 as chld_id, 1 as prnt_id, '3_name' as nm from dual union all
select 4 as chld_id, 1 as prnt_id, '4_name' as nm from dual union all
select 6 as chld_id, 9 as prnt_id, '6_name' as nm from dual union all
select 9 as chld_id, 3 as prnt_id, '9_name' as nm from dual union all
select 12 as chld_id, 9 as prnt_id, '12_name' as nm from dual union all
select 14 as chld_id, 9 as prnt_id, '14_name' as nm from dual union all
select 15 as chld_id, 3 as prnt_id, '15_name' as nm from dual union all
select 18 as chld_id, 9 as prnt_id, '18_name' as nm from dual
)
Если решать именно поставленную задачу, то нужно просто поменять последовательность столбцов и отсортировать.
Джойнить таблицу саму на себя нужно, если в выборке требуется не только ID родительского элемента, но и его имя.
select
prnt_id, chld_id, nm
from t
where prnt_id is not null
order by 1,2
Можно поиграться чтоб увидеть всю иерархию:
select
prnt_id
,chld_id
,level
,lpad(' ', 4*level)||nm as hierarchy_
from t
start with prnt_id is null
connect by prior chld_id = prnt_id
order by prnt_id nulls first, chld_id;
(только не на больших таблицах в скоростном продакшне)