sql - Postgresql select and subselect in same table -


i have following tables:

table person: id |      name | ---------------+  1 |      adam |  2 |     chris |  3 |     nancy |  4 |  nathalie |  5 |      holy |   table relation: id | person | parent | ---+--------+--------+  1 |      2 |      1 |  2 |      2 |      3 |  3 |      1 |      4 |  4 |      5 |      2 |  

i have query produces similar this:

person |   parent | -------+----------+  chris |     adam |  chris |    nancy |   adam | nathalie |   holy |    chris | 

i'm not sure how achieve desired result.

the relation table shows people's parents are. need join person tables (twice) translate ids names:

select p1.name, p2.name   relation r join   person p1 on p1.id = r.person join   person p2 on p2.id = r.parent 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -