我有像
这样的表格id | name | manager
1 | A | 0
2 | B | 1
3 | C | 2
4 | D | 1
我想要每个员工姓名以及经理姓名和身份证。
答案 0 :(得分:1)
http://sqlfiddle.com/#!9/438dd7/2
SELECT e.*,
e1.name
FROM employee e
LEFT JOIN employee e1
ON e.manager = e1.id
答案 1 :(得分: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
希望它能帮到你