我有桌子
Department: id, name
Employee: id, departmentId, name, surname
departmentId是外键引用部门(id) 查询:
SELECT * FROM Employee WHERE Employee.departmentId = Department.id;
返回错误“where子句中的未知列Department.id”
我无法发出此错误。我该如何解决这个问题?
由于
答案 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;