on子句中的未知列甚至列都存在

时间:2017-09-29 12:59:52

标签: mysql

以下MySQL 5.7.19脚本引发错误Error Code: 1054. Unknown column 'ps.employeeId' in 'on clause'

SELECT
    `ps`.`employeeId`
FROM
    tablePS AS `ps`,
    tableFO AS `fo`
LEFT JOIN
   tableWA AS `wa`
ON
    `wa`.`employeeId` = `ps`.`employeeId`

脚本运行没有错误是我删除了FROM子句中的第二个表

,
        tableFO AS `fo`

或替换ON子句

    `wa`.`employeeId` = `ps`.`employeeId`

    `wa`.`employeeId` = 4

您可以使用这些命令

创建表
CREATE TABLE tablePS (
    `id` INT UNSIGNED auto_increment,
    `employeeId` INT UNSIGNED,
    PRIMARY KEY `id` (`id`)
);

CREATE TABLE tableFO (
    `id` INT UNSIGNED auto_increment,
    PRIMARY KEY `id` (`id`)
);

CREATE TABLE tableWA (
    `id` INT UNSIGNED auto_increment,
    `employeeId` INT UNSIGNED,
    PRIMARY KEY `id` (`id`)
);

出了什么问题?

1 个答案:

答案 0 :(得分:1)

尝试

SELECT
    `ps`.`employeeId`
FROM
    tablePS AS `ps`
CROSS JOIN
    tableFO AS `fo`
LEFT JOIN
   tableWA AS `wa`
ON
    `wa`.`employeeId` = `ps`.`employeeId`