How to work with row parents in postgresql?

I have a table with two columns: scopename

and hers parent name

.
https://www.dropbox.com/s/qsajdyzs5hwt6zg/table.jpeg?dl=0

enter image description here


I want to get a tree so I can get the data in the application easily. As these

https://www.dropbox.com/s/48da6vg694estg8/table2.jpeg?dl=0

enter image description here


How can i do this? please, help! I cannot change the db or table structure.
Postscript I am using postgresql

.
P.S2. There's a simple part of the table, maybe 4 or even 5 parentsscopename

+3


source to share


1 answer


I think you want to do a recursive join.

Here's an example: Postgresql Recursive Self-Connecting



And here is the PostgreSQL doc: http://www.postgresql.org/docs/current/static/queries-with.html

+1


source







All Articles