sql - How to reverse the results of this query? -
i'm using firebird 2.1. there table name folders, these fields:
folderid parentfolderid foldername
parentfolderid -1 if it's root folder - otherwise contains parent folder's id.
the following recursive query return parents of folder, in order:
with recursive hierarchy (folderid, parentfolderid, foldername) ( select folderid, parentfolderid, foldername folders folderid = :folderid union select folderid, parentfolderid, foldername folders f join hierarchy p on p.parentfolderid = f.folderid ) select list(folername, ' \ ') hierarchy
the result like:
child \ parent \ parent's parent
how can reverse results of above query get:
parent's parent \ parent \ child?
thank you!
the order of values returned list
undefined.
you may try wrapping query subselect:
with recursive hierarchy (folderid, parentfolderid, foldername, rn) ( select folderid, parentfolderid, foldername, 1 folders folderid = :folderid union select folderid, parentfolderid, foldername, p.rn + 1 folders f join hierarchy p on p.parentfolderid = f.folderid ) select list(foldername, ' \ ') ( select * hierarchy order rn desc )
, however, not guaranteed work , if accident, can break new version.
Comments
Post a Comment