I have a table in the form of linked list.
| unique_id | next |
| -------- | ------- |
| 1 | 3 |
| 2 | null |
| 3 | 2 |
Here the unique_id is the id of the row. Next is the id of the row it is pointing to. There is another table which keeps track of the head. Let's say row with uId=1 is the head. So, I want to query my table such that it extracts head from the headTable and gives the data in the same order as this linked-list. 1->3->2 in the form of an array of rows.
Expected Result : [{unique_id:1, next:3},{unique_id:3, next:2}{unique_id:2, next:null}] Sorry, I'm unable to render the above table properly that's why It's in the form of code.