![enter image description here](https://i.stack.imgur.com/n9AGj.png)

I have a table as above. How can I use self join to get the output sequentially as below?

1. Preheat an oven to 220 degrees C.
2. Peel four potatoes.
3. Cut potatoes into slices.
4. Toss sliced potatoes with oil.
5. Bake in the preheated oven for 20 minutes.
6. Season the hot slices with salt and pepper.

```
select A.content
from recipe A
left join 
(select 
CASE WHEN previous_id IS NULL THEN 0 ELSE previous_id END previous_id, 
CASE WHEN next_id IS NULL THEN 0 ELSE next_id END next_id 
from recipe order by previous_id) B
on B.next_id = A.id;

```

How do I use previous\_id here?

DDL statements for recreating the table 

```
create table recipes (id int, content varchar(50) , previous_id int, next_id int);
insert into recipes (id, content, previous_id, next_id) values (1, 'Preheat an oven to 220 degrees C.', NULL, 2);
insert into recipes (id, content, previous_id, next_id) values (2, 'Peel four potatoes.', 1, 4);
insert into recipes (id, content, previous_id, next_id) values (3, 'Toss sliced potatoes with oil.', 4, 6);
insert into recipes (id, content, previous_id, next_id) values (4, 'Cut potatoes into slices.', 2, 3);
insert into recipes (id, content, previous_id, next_id) values (5, 'Season the hot slices with salt and pepper.', 6, NULL);
insert into recipes (id, content, previous_id, next_id) values (6, 'Bake in the preheated oven for 20 minutes.', 3, 5);

```