1

Good afternoon, I’m trying to fulfill the request while writing an error. Error # 1066 does not quite understand how it can be fixed in my particular case. Perhaps the problem is that I connect to the table several times and need an alias.

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` 
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
  • 1
    You are invoking workplan 4 times you need 3/4 aliases 1 for each invocation otherwise mysql has no idea which invocation is in play. AND you should not mix comma joins an explicit joins.'f you mix comma joins with the other join types when there is a join condition, an error of the form Unknown column 'col_name' in 'on clause' may occur' - https://dev.mysql.com/doc/refman/8.0/en/join.html – P.Salmon Jun 20 '20 at 10:27

1 Answers1

0

I suspect (by your SELECT list of columns) that you want to join employees to the other tables.
For every join you must specify in the ON clause the columns that relate the 2 tables and it is a good practice to use aliases for the tables which shorten the code and make it more readable:

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 

Replace the ? with the names of the columns that relate employees with WorkPlan.

forpas
  • 160,666
  • 10
  • 38
  • 76