Reputation: 109
I want to retrieve the employee name with the name of their manager.
For example:
Employee_Lastname: WARX
Employee_Firstname : CYNTHIA
MANAGER_NANE: SMITH
Warx Cythnia has tha manager with Manager_ID=7369 who is Smith John because Smith has the Employee_ID=7369
I want to create the MANGER_NAME column and add data...
Upvotes: 0
Views: 2338
Reputation: 239814
Normally, you wouldn't store such information. But you can easily obtain it when querying:
select
t1.Employee_Lastname,
t1.Employee_Firstname,
t2.Employee_Lastname as manager_name
from [table] t1
left join
[table] t2
on
t1.manager_id = t2.employee_id
Upvotes: 1
Reputation: 263883
maybe you only want to project the value of the record and not by adding new column in your table right? you only need to join this,
SELECT a.*,
b.Employee_LastName AS MANAGER_LASTNAME
FROM EmpTable a
LEFT JOIN EmpTable b
ON a.Manager_ID = b.Employee_ID
or
SELECT a.Employee_LastName,
a.Employee_FirstName,
b.Employee_LastName AS MANAGER_LASTNAME
FROM EmpTable a
LEFT JOIN EmpTable b
ON a.Manager_ID = b.Employee_ID
Upvotes: 1