如何获取主管名称

时间:2016-12-07 05:54:41

标签: oracle

我必须解决一个问题

我有两个表,如员工和主管

Employees table
------------------------             
firstname    
lastname    
employeeid


Supervisors table
---------------             
supervisor(employeeid)    
employeeid (employeeid)    
and other columns,

益智:

从此我必须通过从Supervisors表中获取主管来从employees表中获取Supervisor名称。

提前致谢

1 个答案:

答案 0 :(得分:1)

SELECT FirstName, LastName 
FROM Employees 
WHERE Employeeid IN (
  SELECT Distinct supervisor FROM Supervisors
)

OR

SELECT DISTINCT a.FirstName, a.LastName
FROM Employees a
INNER JOIN Supervisors b ON a.EmployeeID = b.supervisor

更新:

SELECT b.FirstName, b.LastName, c.FirstName, c.LastName
FROM Supervisors a
LEFT JOIN Employees b ON a.EmployeeID = b.supervisor
LEFT JOIN Employees c ON a.EmployeeID = c.employeeid