MySQL 1054错误 Unknown column .... in 'on clause'
2012-02-17 16:16
423 查看
ERROR 1054 (42S22): Unknown column ... in 'on clause'
原因:MySQL5.0 Bug, 要把联合的表用括号包含起来才行:
例:
Sql代码
SELECT (c.id, a.id, b.id) FROM A a, B b LEFT JOIN C c ON c.a_id = a.a_id AND c.b_id = b.b_id
这句话执行应该是没有错误的,但是Mysql 5 下执行则会出错。
因为mysql下有这样一个BUG,要把联合的表用括号包含起来才行:
Sql代码
SELECT (c.id, a.id, b.id) FROM (A a, B b) LEFT JOIN C c ON c.a_id = a.a_id AND c.b_id = b.b_id
但是HQL生成就是这样的语句,怎么办呢?我们可以改变HQL的写法来达成生成另一种SQL语句,以避免这种BUG的出错
把select (c.id, a.id, b.id) from C c Left join c.a a Left join c.b b
则会生成
Sql代码
SELECT (c.id, a.id, b.id) FROM A a LEFT JOIN B b LEFT JOIN C c ON c.a_id = a.a_id AND c.b_id = b.b_id
这样的话mysql下就不会出错了。
相关文章推荐
- mysql下出现Unknown column 'xx' in 'on clause'的完全解决方法
- (原)mysql错误1093 You can't specify target table 'wms_cabinet_form' for update in FROM clause
- MySQL "You can't specify target table 'X' for update in FROM clause" 错误解决方法
- mysql 一个较特殊的问题:You can't specify target table 'wms_cabinet_form' for update in FROM clause
- 解决mysql不能修改(You can't specify target table 'basic_data' for update in FROM clause)
- MySQL 1054错误 Unknown column .... in 'on clause'
- ERROR 1054 (42S22): Unknown column 'plugin' in 'mysql.user'
- 低级错误之 Unknown column 'XX in 'XXclause'
- MYSQL 临时表 #1093 - You can't specify target table 'dealer_admin' for update in FROM clause
- mysql 5.7 版本,密码无法登陆,更改密码时出现ERROR 1054 (42S22): Unknown column 'password' in 'fie
- mysql删除数据库重复数据,#1093 - You can't specify target table 'blur_article' for update in FROM clause 错误解决方
- 【mysql 】sql删除重复记录 You can't specify target table '表名' for update in FROM clause
- 'WHERE' is the same of 'on' in mysql(many times,but not always)
- 【mysql】【报错】Mysql外键名重复的错误:duplicate key in table '#sql-*'
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tbl_contact' in 'where clause'.
- java.sql.SQLException:Unknown column 'admin' in 'where clause'错误问题
- 错误代码: 1054 Unknown column 't.createUsrId' in 'group statement'
- MySQL 编译出现 error: 'SSL_OP_NO_COMPRESSION' undeclared (first use in this function) 错误
- MySQL修改my.ini后,出现错误:Incorrect information in file: './xx/xx.frm
- [Django](1093, "You can't specify target table 'fee_details_invoices' for update in FROM clause") 错误