FAMILY
ID NAME P_ID
1 Grnd Fath NULL
2 Fath 1
3 Brot1 2
4 Brot2 2
5 Son_brot1 3
6 Son_brot2 4
How can I find below records from above table?
NAME PARENT NAME
Fath Grnd Fath
Brot1 Fath
Brot2 Fath
Son_brot1 Brot1
Son_brot2 Brot2
答案 0 :(得分:1)
SELECT f.NAME, f2.NAME as PARENT_NAME
FROM FAMILY f
INNER JOIN FAMILY f2 ON f.P_ID=f2.ID