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
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):
Note that I used
groupnoinstead ofGROUPas the column name, becauseGROUPis a reserved word and should not be used as a column name.