WHERE子句中的SQL错误

时间:2013-04-18 17:38:10

标签: mysql sql mysql-error-1054

我有桌子

Department: id, name
Employee: id, departmentId, name, surname

departmentId是外键引用部门(id) 查询:

SELECT * FROM Employee WHERE Employee.departmentId = Department.id;

返回错误“where子句中的未知列Department.id”

我无法发出此错误。我该如何解决这个问题?

由于

3 个答案:

答案 0 :(得分:5)

您需要实际包含department

SELECT * 
FROM Employee 
JOIN Department
   ON Employee.departmentId = Department.id;

这使用了ANSI标准的显式JOIN语法。你应该避免隐式连接。

答案 1 :(得分:0)

那是因为你的Department表不在你的FROM子句中。包括它。

select *
from Employee, Department
where Employee.departmentId = Department.id

答案 2 :(得分:0)

您未在from子句中包含部门....

SELECT * FROM Employee, Department WHERE Employee.departmentId = Department.id;