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 7923697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:24:13+00:00 2026-06-03T17:24:13+00:00

I need to develop a good table structure for creating a sortable multilevel list

  • 0

I need to develop a good table structure for creating a sortable multilevel list using SQL Server Database.

Here is an example of the way I develop sortable multilevel lists:

A
├──B
|  ├──E
|  ├──F
|  ├──O
|
├──C
|  ├──M
|

My table structure:

ID   Title   Parent   Sort
---------------------------
1    A       Null     0
2    B       A        0
3    E       B        0
4    F       B        1
5    O       B        2
6    C       A        1
7    M       C        0

Now, would you mind telling me the best way of developing such lists?
Thank you very much indeed.

  • 1 1 Answer
  • 0 Views
  • 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-06-03T17:24:14+00:00Added an answer on June 3, 2026 at 5:24 pm

    Just go with your outlined structure. SQL Server supports recursive queries via CTEs, something like this will do the trick for you:

    WITH tree AS (
      SELECT id, name, parent,
             0 AS level,
             CAST(sort AS varchar(90)) AS path,
             CAST(name AS varchar(90)) AS fullname
        FROM test WHERE parent IS NULL
      UNION ALL
      SELECT t.id, t.name, t.parent, tree.level + 1,
             CAST(tree.path + '.' + CAST(t.sort AS varchar) AS varchar(90)),
             CAST(tree.fullname + '.' + t.name AS varchar(90))
        FROM test t
        JOIN tree ON t.parent = tree.name
    )
    SELECT id, name, parent, level, path, fullname FROM tree
    ORDER BY path;
    

    I’m building some extra informative fields here:

    • level, indicating depth of the node from the root;
    • path, which is built based on your sort field and is used to sort the tree properly;
    • fullname — just a nice view on the full node name.

    You can try this query here.

    Please, consider the size of your data — for huge data structures you might want to push predicates into the inner query for better performance.

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

Sidebar

Related Questions

I need to develop an application which stores data in a SQL Server 2005
ppl, I've to develop a Database like this, Here, I've a list of words.
I need to develop an application in java, which uses a client[embedded server]-server-(-server)-(...) approach.
I need to develop a client server system where I can have multiple clients
I need to develop an application for mobile devices. I'm good in .Net and
i need to develop an sms service from iis web server. Iam new to
I need to develop a Stock Tracker Application using Google Finance API . i
I need to develop a script using Wordpress PHP that will run with the
I've used MATLAB on and off before, but I need to develop a good
I need to develop a application for a user's management in a IT Project.

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.