You can't specify target table 'compares' for update in FROM clause mysql错误总结之一
来源:互联网 发布:unity3d怎么加控制 编辑:程序博客网 时间:2024/06/05 18:22
今天在做sql语句练习的时候遇到这样一个题目:删除除了id之外的其他字段完全相同的记录(留下id较大的记录)。
我用的就是这样一张表compares,按照题目的意思。如果sql语句执行成功,应该只剩下2,3,4,5这四条记录。
我的思路是
1.先将id最大的并且其他字段相同的记录选出来。
select MAX(id) from compares GROUP BY (col1+col2+col3)
结果如下:
2.下面就是删除id不在其中的数据。
delete from compares where id not in (select MAX(id) from compares GROUP BY (col1+col2+col3));
结果如下:
这个错误的意思是说,不能先选出表中的某些值,再更新这张表。
3.针对这个错误,我决定通过中间表来过渡一下。红色部分是较之前多出来的部分。
delete from compares where id not in (select * from(select MAX(id) from compares GROUP BY (col1+col2+col3)) t );
结果就出来了。
0 0
- You can't specify target table 'compares' for update in FROM clause mysql错误总结之一
- mysql中You can't specify target table for update in FROM clause错误
- MySQL "You can't specify target table 'X' for update in FROM clause" 错误解决方法
- Mysql 错误 Code: 1093. You can't specify target table for update in FROM clause
- mysql中You can't specify target table for update in FROM clause错误
- mysql中You can't specify target table for update in FROM clause错误
- mysql中You can't specify target table for update in FROM clause错误
- mysql中You can't specify target table for update in FROM clause错误 转
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- mysql中You can\'t specify target table for update in FROM clause错误
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- mysql中You can't specify target table for update in FROM clause错误
- mysql 中 You can't specify target table <tbl> for update in FROM clause 错误解决方法
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- mysql中You can't specify target table for update in FROM clause错误
- 关于mysql "You can't specify target table 'test_zb_scene' for update in FROM clause"的错误
- mysql 出现You can't specify target table for update in FROM clause错误的解决方法
- mysql中You can’t specify target table for update in FROM clause错误解决方法
- RecyclerView 数据绑定
- 链表经典算法题实现
- if any if ever if anything
- 『学习』MySQL实践
- 如何关闭Win7桌面窗口自动排列和吸附?
- You can't specify target table 'compares' for update in FROM clause mysql错误总结之一
- Microsoft Visual C++ Package Server 已停止工作
- 2-HDFS介绍
- NGUI 九宫格切图
- 编程实现strcmp函数
- static静态代码块执行顺序
- 零编程经验的我是如何找到工作的
- Android面试复习
- 详细探究Spark的shuffle实现