How to generate the order if you know the next item for each item? - Mailing list pgsql-sql

From Rockdale Green
Subject How to generate the order if you know the next item for each item?
Date
Msg-id CAArxxWj=_gc=6RL0QGPzpbXMLZTvxDOqG-sQVxbpCmVu5Q2jpQ@mail.gmail.com
Whole thread Raw
Responses Re: How to generate the order if you know the next item for each item?
List pgsql-sql
Hi, all:

I have two tables one is a lookup for all the tasks, another table stores the next task for each task, I want to generate a list of tasks with its sequence number, can I do it in one query? 

Table task

id  name 
1   postoffice
2   grocery store
3.  walk dog
4.  swimming 
5   roller skate
7   biking


table next_task

task   next_task
3         7
7         1
1          4
4          2
2          5

and I want to get the list in order 

task                task_order 
3 (walk dog)              1
7 (biking)                   2
1 (postoffice)             3  
4 (swimming)             4
2 (growcery store)      5
5 (roller skate)            6

It might be just very simple and I have tried but somehow I am blocked. 

Thanks in advance
-Rockdale 


pgsql-sql by date:

Previous
From: Steve Midgley
Date:
Subject: Re: Equivalent of InternalRowsAffected in NonExecuteQuery for PostgreSQL
Next
From: "David G. Johnston"
Date:
Subject: Re: How to generate the order if you know the next item for each item?