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

I have an Employees table which has emp_id and manager_id both, I want to find out emoloyee_name and manager_name using self join

I am getting this error. and don’t understand where did i go wrong?

Error Code: 1052. Column ‘FIRST_NAME’ in field list is ambiguous

I tried doing this as below but unable to find an answer….

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

SELECT E.EMP_ID, CONCAT(FIRST_NAME,' ',LAST_NAME) AS EMPLOYEE_NAME,
CONCAT(FIRST_NAME,' ',LAST_NAME) AS MANAGER_NAME
FROM EMPLOYEES AS E JOIN EMPLOYEES AS M
ON(E.MANAGER_ID = M.EMP_ID);

>Solution :

Correct code should be like this like @jarlh said in comments

SELECT E.EMP_ID, CONCAT(E.FIRST_NAME,' ',E.LAST_NAME) AS EMPLOYEE_NAME,
    CONCAT(E.FIRST_NAME,' ',E.LAST_NAME) AS MANAGER_NAME
    FROM EMPLOYEES AS E JOIN EMPLOYEES AS M
    ON(E.MANAGER_ID = M.EMP_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