0

enter image description here

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...

2
  • Have you tried anything? This is a basic join query in SQL. Commented Dec 18, 2012 at 14:44
  • Which DBMS are you using? Oracle? PostgreSQL? DB2? Commented Dec 18, 2012 at 14:44

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.