Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

VLOOKUP Equivalent in SQL Within the Same Table

I am trying to lookup a manager’s name from only the Employee_ID, Manager_ID, Employee Name within the same table.

Here is the data I have to work with.

SELECT EmployeeID, EmployeeName, Employee_Job_Title, Manager_ID, Managers_Position

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I’d like the results to look like:

EmployeeID EmployeeName Employee_Job_Title Manager_ID ManagerName Managers_Position
1234 Jason Teller 2345 Mason Teller Manager

I know this can happen based on some type of join on the EmployeeIDs but I’m not sure how to make it happen.

Thanks for the help!!

>Solution :

select
    e.EmployeeID,
    e.EmployeeName,
    e.Employee_Job_Title,
    e.Manager_ID,
    m.EmployeeName as ManagerName,
    e.Managers_Position
from employee_table e
left join employee_table m on e.Manager_ID = m.Employee_ID
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading