我有一个表T,包含以下列 - ID_Employee(主键) - NAME_Employee - ID_Manager(同一个表上的外键)
为了显示表格的行,我这样做: SELECT ID_Employee,NAME_Employee,ID_Manager FROM T
但是如何显示经理的NAME而不是他的ID? 我是SQL的初学者:)
由于
答案 0 :(得分:2)
欢迎使用Stack Overflow!
试试这个:
SELECT a.ID_Employee,
a.NAME_Employee,
b.ID_Employee AS ManagerID,
b.Name_Employee AS Manager
FROM T a
INNER JOIN T b
ON a.ID_Manager = b.ID_Employee