I have the tables

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

departmentId is a foreign key referencing Department(id) The Query:

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

returns the error "Unknown column Department.id in where clause"

I can't place this error. How do i fix this?

Thanks

有帮助吗?

解决方案

You need to actually include the department table

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

This uses explicit JOIN syntax which is ANSI standard. You should refrain from implicit joins.

其他提示

That's because your Department table is not in your FROM clause. Include it.

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

You aren't including Department in your from clause....

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top