I have columns id
(string), parentId
(string or null) and order
(number). It’s tree like structure where rows with the same parentId
are children of the same node. order
is used to sort children for each parent (so they might be the same for childs of different parents).
For a given id
, I want to extract its previous and next row. I need to somehow sort data first by parentId
looking at its order
and then isnert in the middle of table their childrens, again sorted by order
and again (recursion). Here is how my data looks like after running query:
SELECT "content"."id", "content"."parentId", "content"."order" FROM "course_content_entity" "content" WHERE ( "content"."deletedAt" IS NULL ) AND ("content"."courseId" = '05dd28d5-a244-4ca1-b7fb-fc3bc7b2e422') order by "content"."parentId", "content"."order"
enter image description here
It’s of course now what I want. Any ideas how to do that?
Korer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.