mysql You can't specify target table for update in FROM clause解决方法
2024-08-26 17:54:55
mysql You can't specify target table for update in FROM clause解决方法
出现这个错误的原因是不能在同一个sql语句中,先select同一个表的某些值,然后再update这个表。
<pre>
mysql> update message set content='Hello World' where id in(select min(id) from message group by uid);
ERROR 1093 (HY000): You can't specify target table 'message' for update in FROM clause
</pre>
因为在同一个sql语句中,先select出message表中每个用户消息的最小id值,然后再更新message表,因此会出现 ERROR 1093 (HY000): You can’t specify target table ‘message’ for update in FROM clause 这个错误。
解决方法:select的结果再通过一个中间表select多一次,就可以避免这个错误
<pre>
update message set content='Hello World' where id in( select min_id from ( select min(id) as min_id from message group by uid) as a );
</pre>
最新文章
- poj 1572
- macOSX 访问 win7共享文件
- Delphi开发的IP地址修改工具
- VNC+SSH相关应用
- 关于sources.list和apt-get [转载]
- (原创)LAMP教程2-安装虚拟机软件VirtualBox
- Python之路,Day4 - Python基础4 (new版)
- android 再按一次退出程序(实现代码)
- 【转】char *str 和 char str[]的区别
- 积累的VC编程小技巧之属性页
- Bug记录:微博的Java SDK返回经纬度错误
- PDO详解
- word建立统一的表格样式
- RSA加解密实现
- 20170310 - Python 3 下 SQLAlchemy 的 MySQL 数据库 URI 配置
- Android-PickerView【仿iOS的PickerView控件,并封装了时间选择和选项选择这两种选择器】使用
- JavaScript 作用域、命名空间及闭包
- faster rcnn
- Helm: Error: no available release name found
- Docker(十三)-Docker save and load镜像保存
热门文章
- Poj 1743 Musical Theme(后缀数组+二分答案)
- Linux下多线程模拟停车场停车
- Large Kernel Matters —— Improve Semantic Segmentation by Global Convolutional Network(GCN全局卷积网络)
- 2018-2019-2 网络对抗技术 20165322 Exp9 Web安全基础
- ubuntu之路——day7.2 regularization
- python 图形
- file_get_contents(";php://input";)
- The Matrix | 黑客帝国
- iis网站搭建http访问的文件服务器
- Java 8 新特性总结