mysqlmysql-error-1052

MySQL: "Column 'column_name' in where clause is ambiguous"


I JOIN 2 tables

for example

table_A
+---------+-----------+-----------+
| user_id | ticket_id | user_name |
+---------+-----------+-----------+

table_B
+-----------+-------------+
| ticket_id | ticket_name |
+-----------+-------------+

If I run the following query:

SELECT
  table_A.user_id
, table_A.user_name
, table_B.ticket_name
FROM table_A
LEFT JOIN table_B ON table_B.ticket_id = table_A.ticket_id
WHERE ticket_id = '1';

On the live server we get the error: "Column 'ticket_id' in where clause is ambiguous"
On the the test server the query is accepted.

I know how to solve the error, that's not the problem.

I would however be very happy if our test server would NOT accept this query and (just like the production server) throw an error.

Does anybody know if there is some kind of setting that would make the test server throw an error just like the live server?

P.S.
MySQL version on Test server: 5.0.32-Debian_7etch5-log
MySQL version on Live server: 5.0.41-community-log


Solution

  • There are a similar issues with MS SQLServer where version 2000 is accepting some ambiguous queries and the 2005 would throw an error. Basically the newer versions seem to be more strict.

    As a general rule you should use the same DB version both on Test server and on Production server to avoid this type of behaviour where a piece of code works on the test machine and fails on production.