I have some locality tables in a PostgreSQL database:
Table loc -- the places themselves
---------
| id | name
| 1 | Park X
| 2 | City A
| 3 | City B
Table locdad -- the hierarchical relationship between places
------------
| id | dad | loc
| 1 | 2 | 1
| 1 | 3 | 1
This describes a National Park "X" that covers city A and city B, i.e. the park has two "fathers" in the hierarchical scheme.
When I do a joined query, I get two lines for this park:
select l.id,l.name loc,l1.name dad
from loc l
join locdad ld on ld.loc = l.id
join loc l1 on l1.id = ld.dad
where l.id=1
| id | loc | dad
| 1 | Park X | City A
| 1 | Park X | City B
I would like to combine the result into:
| id | loc | dad
| 1 | Park X | City A, City B
How can I do that?