2015-10-18 59 views
-1

我有表像如何使用加入

id  | name  | manager 
1  | A  | 0 
2  | B  | 1 
3  | C  | 2 
4  | D  | 1 

,我想與經理的姓名和ID沿着每個員工的名字。

回答

1

說你的表名員工和經理

SELECT 
e.id, 
e.name AS empname, 
m.name AS managername 
FROM employee AS e 
INNER JOIN manager AS m ON e.manager = m.id 

希望它會幫助你