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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:07:36+00:00 2026-06-15T15:07:36+00:00

I have a single table that lists dependencies and I can’t figure out how

  • 0

I have a single table that lists dependencies and I can’t figure out how I can sort this in the actual order the diagram is displayed (using DB2 SQL)

Diagram (Lists out the GROUP)
34 -> 23 -> 65 ->….

The goal is to sort in the order of the diagram

The Table has two fields GROUP and DEPEND. The ideal first column would be 34,0 (0 since it is dependent on nothing) followed by 23,34 (dependent on GROUP 34), followed by 65,23 (dependent on GROUP 23). Following the pattern of GROUP, DEPEND.

So the results would be as follows:

 1. GROUP   DEPEND
 2. 34      0
 3. 23      34
 4. 65      23

Is it possible to use a variable or something to view the previous record’s GROUP to determine the next row?

Thanks so much for any assistance or ideas

  • 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-15T15:07:37+00:00Added an answer on June 15, 2026 at 3:07 pm

    Current versions of DB2 support recursive queries, so the following should work (at least it does with my DB2 9.7 Express-C on Windows):

    with dep_tree  (groupno, depend, group_order) as (
       select groupno, depend, 1 as group_order
       from group_list
       where depend = 0
    
       union all 
    
       select c.groupno, c.depend, p.group_order + 1
       from group_list c, 
            dep_tree p 
       where p.groupno = c.depend
    )
    select group_order, groupno, depend
    from dep_tree
    order by group_order;
    

    Note that I used groupno instead of GROUP as the column name, because GROUP is a reserved word and should not be used as a column name.

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

Sidebar

Related Questions

I'm working on a project that will have a single table holding lots and
Background I have a dimension table that has a single record for each day.
Here's the caveat... If you have a table that has a single column and
I have a feed that is populating a single text field in a table
I have a single table that contains two types of items under the same
I have two tables that are considered a single entity in my domain model.
I have several database tables that just contain a single column and very few
I have a query that transfers data from multiple slave tables into a single
I have two tables described below. What I need is a single query that
I have a single product table with multiple fields which contain user evaluations of

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.