Search code examples
mysqlsqlmysql-error-1054

SQL Error in WHERE clause


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


Solution

  • 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.