I'm using Firebird 2.1. There is a table name Folders, with these fields:
FolderID
ParentFolderID
FolderName
ParentFolderID is -1 if it's the root folder - otherwise it contains the parent folder's ID.
The following recursive query will return the parents of a folder, in order:
WITH RECURSIVE hierarchy (folderid, ParentFolderId, FolderName) as (
SELECT folderid, ParentFolderId, FolderName
FROM folders
WHERE folderid = :folderid
UNION ALL
SELECT folderid, ParentFolderId, FolderName
FROM folders f
JOIN hierarchy p ON p.parentFolderID = f.folderID
)
SELECT List(FolerName, ' \ ') FROM hierarchy
The result will be something like:
Child \ Parent \ Parent's parent
How can I reverse the results of the above query to get:
Parent's parent \ Parent \ Child?
Thank you!