sorting rows by a follow-up sequence

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    sorting rows by a follow-up sequence

    Hi,

    I’ve got a table, where I need to sort IDs in a way, that the previous ID is referenced by the next row’s 'Prev_ID' field. (It’d also be possible to use Follow_ID instead of Prev_ID accordingly, if that’s easier)

    table:
    Code:
     ID | Prev_ID
    ––––+–––––––––
      1 |  NULL
      2 |   10
      3 |   17
    …
     10 |    1
    …
     17 |    2
    …
     33 |    3
    the sort order I want to achieve is: 1 - 10 - 2 - 17 - 3 - 33 - …, but I have no idea, how to do that (cursors?). could anyone point me into the right direction?

    Thanks, Dormi
Working...