Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 477273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:34:27+00:00 2026-05-13T00:34:27+00:00

I have a flat list of pages in a mySQL Table. ID | Tab

  • 0

I have a flat list of pages in a mySQL Table.

ID    | Tab index | Page Name | parent 

Pages can be children of another page, specified by the “parent” property.

The whole list is sorted using the “Tab index” int column.

Can anybody think of a way to query this list so that

  • Items are ordered by Tabindex

  • Items that are children of another item are grouped behind the parent item, and ordered by their tabindices (optional)?

My mySQL knowledge doesn’t reach that deep.

This is an existing data structure and can’t be changed.

Thanks in advance for any input.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:34:28+00:00Added an answer on May 13, 2026 at 12:34 am

    Assuming columns id, pagename, tabindex, parent_id

    select *,
        coalesce(
            tabindex,
            (select p2.tabindex from page as p2 where p2.id = p.parent_id limit 1),
            0
        ) as ti
    from page as p
    order by coalesce(ti, p.tabindex)
    ;
    

    will return those columns in “ti” order which is the first non-null value of the following:

    1. tabindex
    2. the parent’s tabindex
    3. 0

    This lets you leave child tabindexes blank and have them “inherit” from the parent. Also, if you want the default sort value to push to the bottom, you can replace the 0 (third arg in coalesce) with (select max(tabindex) + 1 from page). The only caveat is that if a child tabindex is larger than the following parent, it will appear later in the list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a flat Tcl list. Now I want to append a new element
I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
I have a tab delimited file on a shared path. I've setup that flat
Assume I have the following information in a flat format, for example a list
Lets say I have a flat list of objects, each of which has a
If I have a Publisher table that has many Books, and each Book can
I have a stored procedure that returns a flat list of names that are
I'm trying to convert a sectionned table into a flat list using this function
I have a list of 17 flat files that I'm trying to import into
I've got a flat list of items in a ObservableCollection. These items have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.