我有以下表格格式:
会员
mem_id | mem_name
------------------
1 A
2 B
3 C
项目成员
fk_mem_id | meb_parent_id
-------------------------
1 0
2 1
3 2
我需要这样的结果:
mem_id | child| parent
--------------------------
1 A NULL
2 B A
3 C B
我试过但失败了..有什么想法....?
SELECT pm.*, m1.meb_name as child, m2.meb_name as parent
FROM members m1
LEFT JOIN members m2
ON m1.meb_parent_id = m2.meb_id