免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1831 | 回复: 2
打印 上一主题 下一主题

一个升级Mysql版本后出现的SQL错误 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-01-22 11:14 |只看该作者 |倒序浏览
前段时间升级了Mysql到5.0.16

  1. select distinct a.* from order_main a,order_details b
  2. left join order_history c on c.client_id=a.client_id
  3. where a.id=b.order_id
  4. order by a.id
复制代码



mysql返回错误
#1054 - Unknown column 'a.client_id' in 'on clause'




表设计并没有任何问题,因为我们原来是用4.0的,并没有出现过这个错误





后来解决的方法是改成两个left join,问题解决
SELECT DISTINCT a . *
FROM order_main a
LEFT JOIN order_history c ON c.client_id = a.client_id
LEFT JOIN order_details b ON a.id = b.order_id
ORDER BY a.id




求解这个错误的原因

厄,如果我火星,请BS我吧

论坛徽章:
0
2 [报告]
发表于 2007-01-22 11:44 |只看该作者
MySQL Bugs: #13551: #1054 - Unknown column 'xxxx' in 'on clause'-
Description: LEFT JOIN gives the "#1054 - Unknown column 'xxxx' in 'on clause'" error on MySQL 5, but it's working fine in MySQL 4.1 How to repeat: CREATE TABLE IF NOT EXISTS `t1` ( `id` int(10) unsigned NOT NULL auto_increment, ...

论坛徽章:
0
3 [报告]
发表于 2007-01-22 20:32 |只看该作者
这个是因为新版本中left join和 ( 等运算符的优先级别有关系,记得用括号啥的就可以了
试试看

  1. select distinct a.* from order_main a,order_details b
  2. left join order_history c on (c.client_id=a.client_id)
  3. where a.id=b.order_id
  4. order by a.id
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP