mysql中You can’t specify target table for update in FROM clause错误解决方法
作者:junjie 时间:2024-01-19 02:24:26
mysql中You can't specify target table for update in FROM clause错误的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中)。 例如下面这个sql:
delete from tbl where id in
(
select max(id) from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
)
改写成下面就行了:
delete from tbl where id in
(
select a.id from
(
select max(id) id from tbl a where EXISTS
(
select 1 from tbl b where a.tac=b.tac group by tac HAVING count(1)>1
)
group by tac
) a
)
也就是说将select出的结果再通过中间表select一遍,这样就规避了错误。注意,这个问题只出现于mysql,mssql和oracle不会出现此问题。
标签:You,can’t,specify,target,table,for,update,in,FROM,clause
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python混合使用同步和异步函数的方法
2021-07-19 05:01:05
![](https://img.aspxhome.com/file/2023/6/114766_0s.gif)
Python操作PDF文件之实现A3页面转A4
2021-03-06 19:45:06
![](https://img.aspxhome.com/file/2023/9/69059_0s.jpg)
Mysql锁机制之行锁、表锁、死锁的实现
2024-01-26 08:29:43
![](https://img.aspxhome.com/file/2023/9/122879_0s.png)
python用类实现文章敏感词的过滤方法示例
2022-04-10 19:30:25
![](https://img.aspxhome.com/file/2023/9/95309_0s.png)
vue中的provide/inject的学习使用
2024-04-27 16:08:55
![](https://img.aspxhome.com/file/2023/7/132977_0s.png)
数据库名词解释
2008-09-12 17:28:00
Python中免验证跳转到内容页的实例代码
2021-03-27 11:19:55
![](https://img.aspxhome.com/file/2023/8/99478_0s.png)
Python3下错误AttributeError: ‘dict’ object has no attribute’iteritems‘的分析与解决
2023-04-21 05:52:45
python如何实现代码检查
2022-07-22 18:19:12
以Python的Pyspider为例剖析搜索引擎的网络爬虫实现方法
2022-02-15 19:11:48
详解Python中的null是什么
2022-11-30 15:33:56
![](https://img.aspxhome.com/file/2023/0/67750_0s.png)
(X)HTML Strict 下的嵌套规则
2008-03-08 18:39:00
![](https://img.aspxhome.com/file/UploadPic/20071/200713110533913s.gif)
JS实现css边框样式设置工具
2008-05-25 16:22:00
![](https://img.aspxhome.com/file/UploadPic/20085/25/border-style-tool_82s.gif)
使用cx_freeze把python打包exe示例
2021-06-10 05:36:20
vue中项目页面空白但不报错产生的原因及分析
2024-05-03 15:12:17
![](https://img.aspxhome.com/file/2023/8/130188_0s.png)
python多线程互斥锁与死锁
2023-11-10 14:16:28
![](https://img.aspxhome.com/file/2023/2/121922_0s.png)
使用matplotlib绘制并排柱状图的实战案例
2022-04-06 01:22:25
![](https://img.aspxhome.com/file/2023/7/81627_0s.png)
sqlserver四舍五入使用round函数及cast和convert函数
2024-01-21 18:20:53
Python Flask框架开发之运用SocketIO实现WebSSH方法详解
2021-11-06 01:03:33
![](https://img.aspxhome.com/file/2023/9/133739_0s.png)
使用CSS简单实现垂直居中
2008-06-23 07:32:00
![](https://img.aspxhome.com/file/UploadPic/20086/23/200862374356840s.jpg)