Subject Re: [firebird-support] Common Table Expressions and Sorting
Author Stefan Heymann
with recursive
dept_tree (dept_id, name, lvl, sgn )
as (
select dept_id, name, 0, 0 as lvl
from depts where parent_dept_id is null

union all

select d.dept_id, d.name, h.lvl + 1, 1
from depts d
join dept_tree h on d.parent_dept_id = h.dept_id
)
select z.dept_id, z.sgn, z.lvl, z.name
from dept_tree z
order by z.sgn, upper(z.name)


Thanks, Mimmo. But in your version (I had to correct it to the above)
the nesting gets lost. All levels below root level have a Sign value
of 1 (one). Is that how you intended it to be?

Regards

Stefan