错误 # 1066 - 在 MySQL 中不是唯一的 table / 别名
Error # 1066 - not a unique table / alias in MySQL
下午好,我在尝试完成请求时写错了。 Error # 1066 不太明白在我的特殊情况下如何修复它。也许问题是我多次连接到 table 并且需要一个别名。
SELECT `employees`.`name`, `employees`.`surname`, `employees`.`patronymic`,
`doc`.`name`, `doc`.`agreement`, `tank`.`name`,
`liquid`.`name`, `WorkPlan`.`description`
FROM `WorkPlan` , `employees` , `doc` , `tank` , `liquid`
LEFT JOIN `WorkPlan` ON `tank`.`id` = `WorkPlan`.`id_tank`
LEFT JOIN `WorkPlan` ON `liquid`.`id` = `WorkPlan`.`id_liquid`
LEFT JOIN `WorkPlan` ON `doc`.`id` = `WorkPlan`.`id_doc`
AND `WorkPlan`.`id_tank` = `tank`.`id`
AND `WorkPlan`.`id_liquid` = `liquid`.`id`
AND `WorkPlan`.`id_doc` = `doc`.`id`
我怀疑(根据您的 SELECT
列列表)您想要将 employees
连接到其他表。
对于每个连接,您必须在 ON
子句中指定与 2 个表相关的列,并且最好为表使用别名以缩短代码并使其更具可读性:
SELECT e.name, e.surname, e.patronymic,
d.name, d.agreement,
t.name,
l.name,
w.description
FROM employees e
LEFT JOIN WorkPlan w ON e.? = w.?
LEFT JOIN tank t ON t.id = w.id_tank
LEFT JOIN liquid l ON l.id = w.id_liquid
LEFT JOIN doc d ON d.id = w.id_doc
将 ?
替换为与 employees
和 WorkPlan
相关的列的名称。
下午好,我在尝试完成请求时写错了。 Error # 1066 不太明白在我的特殊情况下如何修复它。也许问题是我多次连接到 table 并且需要一个别名。
SELECT `employees`.`name`, `employees`.`surname`, `employees`.`patronymic`,
`doc`.`name`, `doc`.`agreement`, `tank`.`name`,
`liquid`.`name`, `WorkPlan`.`description`
FROM `WorkPlan` , `employees` , `doc` , `tank` , `liquid`
LEFT JOIN `WorkPlan` ON `tank`.`id` = `WorkPlan`.`id_tank`
LEFT JOIN `WorkPlan` ON `liquid`.`id` = `WorkPlan`.`id_liquid`
LEFT JOIN `WorkPlan` ON `doc`.`id` = `WorkPlan`.`id_doc`
AND `WorkPlan`.`id_tank` = `tank`.`id`
AND `WorkPlan`.`id_liquid` = `liquid`.`id`
AND `WorkPlan`.`id_doc` = `doc`.`id`
我怀疑(根据您的 SELECT
列列表)您想要将 employees
连接到其他表。
对于每个连接,您必须在 ON
子句中指定与 2 个表相关的列,并且最好为表使用别名以缩短代码并使其更具可读性:
SELECT e.name, e.surname, e.patronymic,
d.name, d.agreement,
t.name,
l.name,
w.description
FROM employees e
LEFT JOIN WorkPlan w ON e.? = w.?
LEFT JOIN tank t ON t.id = w.id_tank
LEFT JOIN liquid l ON l.id = w.id_liquid
LEFT JOIN doc d ON d.id = w.id_doc
将 ?
替换为与 employees
和 WorkPlan
相关的列的名称。