以下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`)
);


怎么了?

最佳答案

尝试

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

关于mysql - on子句中的未知列,即使该列存在,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46489356/

10-16 15:17