MySQL:“列‘column_name’” in where 子句不明确”
我联接 2 个表
例如,
table_A +---------+-----------+-----------+ | user_id | ticket_id | user_name | +---------+-----------+-----------+ table_B +-----------+-------------+ | ticket_id | ticket_name | +-----------+-------------+
如果我运行以下查询:
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';
在实时服务器上,我们会收到错误:“where 子句中的列 'ticket_id' 不明确
”
在测试服务器上,查询被接受。
我知道如何解决该错误,这不是问题。
但是,如果我们的测试服务器不接受此查询并且(就像生产服务器一样)抛出错误,我会非常高兴。
有谁知道是否有某种设置会使测试服务器像实时服务器一样抛出错误?
附注
测试服务器上的 MySQL 版本:5.0.32-Debian_7etch5-log
实时服务器上的 MySQL 版本:5.0.41-community-log
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MS SQLServer 也存在类似问题,其中 2000 版接受一些不明确的查询,而 2005 版会抛出错误。 基本上新版本似乎更严格。
作为一般规则,您应该在测试服务器和生产服务器上使用相同的数据库版本,以避免出现这种类型的行为,即一段代码在测试机器上工作但在生产机器上失败。
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.
您的两台服务器的 SQL 模式是什么? 我可以想象其中一个会比另一个更严格。
What SQL mode are your two servers in? I could imagine that one is set to be more strict than the other.
我认为 Tomalak 是对的 - MySQL 管理设置中有一个严格模式可以解决您的问题。
我记得您在数据库创建期间选择了它,但您可以从管理 GUI 中调整它。
目前 MySQL 中存在一些重大错误,如果可以的话,您可能需要考虑迁移到 SQL Server Express...
Sun 陷入财务困境,我不确定 MySQL 将如何结束。
I think Tomalak is right - there is a strict mode in the MySQL Administrative settings that may resolve your issue on the issue.
I recall you select it during db creation, but you can adjust it from the Admin GUI.
There are some significant bugs in MySQL right now, you may want to consider moving to SQL Server Express if you can...
Sun is in financial trouble and I'm not surehow MySQL will end up.