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

  • Home
  • SEARCH
  • 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 759949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:39:30+00:00 2026-05-14T15:39:30+00:00

Take this table: id name sub_id ————————— 1 A (null) 2 B (null) 3

  • 0

Take this table:

id      name      sub_id
---------------------------
1        A        (null)
2        B        (null)
3        A2       1
4        A3       1

The sub_id column is a relation to his own table, to column ID.

 subid --- 0:1  --- id

Now I have the problem to make a correctly SELECT query to show that the child rows (which sub_id is not null) directly selected under his parent row. So this must be a correctly order:

1    A    (null)
3    A2   1
4    A3   1
2    B    (null)

A normal SELECT order the id. But how or which keyword help me to order this correctly?

JOIN isn’t possible I think because I want to get all the rows separated. Because the rows will be displayed on a Gridview (ASP.Net) with EntityDataSource but the child rows must be displayed directly under his parent.

Thank you.

  • 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-05-14T15:39:30+00:00Added an answer on May 14, 2026 at 3:39 pm

    Look at Managing Hierarchical Data in MySQL.

    Since recursion is an expensive operation because basicly you’re firing multiple queries to your database you could consider using the Nested Set Model. In short you’re assigning numbers to ranges in your table. It’s a long article but it worth reading it. I’ve used it during my internship as a solution not to have 1000+ queries, But bring it down to 1 query.

    Your handling ‘overhead’ now lies at the point of updating the table by adding, updating or deleting records. Since you then have to update all the records with a bigger ‘right-value’. But when you’re retrieving the data, it all goes with 1 query 🙂

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

Sidebar

Related Questions

I have a table that looks like this: category category_id name category_seo_friendly_url left_id right_id
So I have this table CREATE TABLE meta ( id BIGINT(20) NOT NULL, type
I have this users table with: id : int (255) name: char (100) last_comment_target:
Take this table WORDS WORD Hello Aardvark Potato Dog Cat And this list: ('Hello',
Take for example this table (let's call it BIN_TABLE ): +------+------+ | A |
Take a look at this table: <table cellpadding=0 cellspacing=0 class=order_form> <tr> <th>Amount</th> <th>Desc</th> <th>Price</th>
to simplify this let take that table: table1 ------------- id unique primary int myVal1
Why does this MySQL query take forever (and never finishes) on a table that
I have a table where a plugin keeps all form submissions, in this table
The stored procedure builds without any problem. The purpose of this is to take

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.