The simplest answer is that only providing a field
reference when MySQL expects a table.field
in a WHERE
clause when more than one table is being queried is like trying to log into a system without providing your username, only your password. Sorry, your going to have to tell the system who's password you have supplied when you want to log in. Key + Datum = result.
Null + Datum = Error.
Taking it a little deeper, MySQL does not make the connection between the two tables as defined in the JOIN statement UNTIL THE QUERY FINISHES. The WHERE
clause is processed in sequence to make sure that the tables are filtered as they are joined. If you want to have it for search both tables for an particular ID#, then you need add the syntax for that. Something like:
`SELECT * FROM employees FULL JOIN people ON employees.id=people.id WHERE (employee.id = 2 OR people.id = 2)`
This is different in that a FULL JOIN will still work when one or the other table doesn't have a match in the common table, it still adds to the result with the empty columns of the missing entry being NULLs.
There is a lot out there on JOINs of the various types including this SO post and it was a dupe of an even older SO post that explains this in better detail.
TL:DR - If your working with one table, MySQL knows where to look. When your working with more than one table, MySQL gets confused easy and needs to know for sure what table your working on. Thats why it throws the error at you. The fix is simple, you need only add two things to the query in the, WHERE clause, something like:
'SELECT * FROM employees LEFT JOIN people ON employees.id=people.id WHERE employee.id = 2'
Adding the LEFT to JOIN gives the server extra instructions for the way your combining the assets and adding the table name with the column name will tell MySQL which table it needs to look at.