关于mysql 5.7版本“报[Err] 1093 - You can't specify target table 'XXX' for update in FROM clause”错误的bug
2017-09-21 19:49
513 查看
不同于oracle和sqlserver,mysql并不支持在更新某个表的数据时又查询了它,而查询的数据又做了更新的条件,因此我们需要使用如下的语句绕过:
本地测试是通过的,但是在上到测试环境的时候,发现还是会报如下错误:
对比版本发现,本地是5.6.25,测试环境是5.7.10,版本高的反而不支持了。只能改用另一种方式实现:
这种写法在各版本都是支持的。语法见UPDATE Syntax
后来发现,这是mysql 5.7.6版本出现的一个bug,并且在5.7.11版本中修复了。参考
UPDATE teaching_department SET code_year = 2017, notice_code = (SELECT a.code + 1 FROM (SELECT MAX(notice_code) code FROM teaching_department WHERE department_id = 6284 and code_year = 2017) a) WHERE id = 106;
本地测试是通过的,但是在上到测试环境的时候,发现还是会报如下错误:
[SQL] UPDATE teaching_department SET code_year = 2017, notice_code = (SELECT a.code + 1 FROM (SELECT MAX(notice_code) code FROM teaching_department WHERE department_id = 6284 and code_year = 2017) a) WHERE id = 106; [Err] 1093 - You can't specify target table 'teaching_department' for update in FROM clause
对比版本发现,本地是5.6.25,测试环境是5.7.10,版本高的反而不支持了。只能改用另一种方式实现:
UPDATE teaching_department, (SELECT MAX(notice_code) code FROM teaching_department WHERE department_id = 6284 AND code_year = 2017) AS t SET code_year = 2017, notice_code = t.code + 1 WHERE id = 7
这种写法在各版本都是支持的。语法见UPDATE Syntax
后来发现,这是mysql 5.7.6版本出现的一个bug,并且在5.7.11版本中修复了。参考
相关文章推荐
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- mysql错误:1093-You can’t specify target table for update in FROM clause的解决方法
- MySQL [Err] 1093 - You can't specify target table 'test' for update in FROM clause
- MySQL报1093错误,MySQL can’t specify target table for update in FROM clause
- MySQL 错误码: 1093 You can't specify target table 'jc_user' for update in FROM clause
- Mysql 错误 Code: 1093. You can't specify target table for update in FROM clause
- mysql中错误:1093-You can’t specify target table for update in FROM clause的解决方法
- (原)mysql错误1093 You can't specify target table 'wms_cabinet_form' for update in FROM clause
- MySQL中执行sql语句错误 Error Code: 1093. You can't specify target table 'car' for update in FROM clause
- 错误:You can't specify target table 'xxx' for update in FROM clause的解决
- mysql 出现You can't specify target table for update in FROM clause错误的解决方法
- mysql删除数据库重复数据,#1093 - You can't specify target table 'blur_article' for update in FROM clause 错误解决方
- MySQL数据库update更新子查询[Err] 1093 - You can't specify target table 'text' for update in FROM clause
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
- 数据库删除重复属性列,错误[HY000][1093] You can't specify target table 'orders' for update in FROM clause
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- MYSQL 临时表 #1093 - You can't specify target table 'dealer_admin' for update in FROM clause
- MySQL错误:You can't specify target table 'tablename' for update in FROM clause
- [Err] 1093 - You can't specify target table 's' for update in FROM clause
- [Err] 1093 - You can't specify target table 'image' for update in FROM clause