我有一个员工表,其中有emp_id和manager_id,我想使用自连接找出emoloyee_name和manager_name

问题描述 投票:0回答:1

我收到此错误。不明白我哪里错了?

错误代码:1052。字段列表中的“FIRST_NAME”列不明确

我尝试按如下方式执行此操作,但找不到答案......

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);
sql mysqli self-join mysql-error-1052
1个回答
0
投票

正确的代码应该像@jarlh在评论中所说的那样

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);
© www.soinside.com 2019 - 2024. All rights reserved.