1

Does PostgreSQL support self joining or is there another way to solve this?

For example, lets say I have a single table (table a) with the following columns:

id     name     supid
------------------------
1       a         2
2       b         3
3       c         4
4       d         5
..      ..        ..

Is there a way to output the data in the following format?

id      name     sup name
-------------------------
1        a        b
2        b        c
3        c        d
4        d        ..
..       ..       ..
4

1 回答 1

3

简单的怎么样JOIN

SELECT a.id,a.name,b.name "sup name"
FROM tablea a
JOIN tablea b
  ON a.supid = b.id

一个用于测试的 SQLfiddle

于 2013-07-06T19:02:39.647 回答