I have MySQL JOIN in roughly the following format:
SELECT DISTINCT employees.empl_id,
employees.name,
departments.dep_id,
departments.name,
buildings.id AS building_id,
buildings.address AS building_address
buildings.department AS building_department
FROM employees
LEFT JOIN employees USING (empl_id)
LEFT JOIN departments USING (dep_id)
LEFT JOIN buildings
ON buildings.department = departments.dep_id
When I run this query I get the error:
ERROR 1054 (42S22) at line 1: Unknown column 'MyDB.employees.dep_id' in 'on clause'
Even tough the column dep_id
really does not exists in employees, I never reference employees.dep_id
in the JOIN, and dep_id
is a column of departments
and not employees!!
Can this be due to mixing the USING
and ON
clause?
This JOIN is part of a script I wrote which was done using MySQL version > 5, and no errors occurred. I am adapting the script to work with an older version of MySQL and ran into this error. mysql --version
yields:
mysql Ver 14.7 Distrib 4.1.22, for pc-linux-gnu (i686) using readline 4.3
I read through this but it did not help me. Any suggestions would be appreciated.