My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Fastest and/or simplest query to build nav from table with "parent" structure?

Jos Faber's photo
Jos Faber
·Jun 7, 2016

What would be the fastest and/or simplest query to build a pretty url with the following table structure

pages
    id
    parent
    slug

in which every node has a slug for building the pretty url. So e.g.

/about/history/intro

would represent the link to the intro page, which is child of history, which is child of about (> is selected)

>about
    >history
        >intro
        photos
    people
contact
disclaimer

Can this be done in one query? Or should it just be recursive until there is no parent?