当前位置:网站首页>You can‘t specify target table ‘kms_report_reportinfo‘ for update in FROM clause
You can‘t specify target table ‘kms_report_reportinfo‘ for update in FROM clause
2022-08-10 05:13:00 【明快de玄米61】
背景
在Mysql数据库中执行下面sql语句的时候,出现了上述错误,原因是:Mysql中不允许直接同一张表查询在更新或者删除
UPDATE t_user
SET STATUS = 3
WHERE
id IN (
SELECT
id
FROM
t_user
WHERE
type = '5')
解决办法
将select得到的结果,再通过中间表select一遍,这样就规避了错误
这个问题只出现于mysql,oracle不会出现此问题。
所以只要将语句做如下修改即可:
UPDATE t_user
SET STATUS = 5
WHERE
id IN (
SELECT
t.*
FROM
( SELECT id FROM t_user WHERE type = '5' ) t)
边栏推荐
- canvas 画布绘制时钟
- JS gets the year, month, day, time, etc. of the simple current time
- Concurrency tool class - introduction and use of CountDownLatch, CyclicBarrier, Semaphore, Exchanger
- [Web3 Series Development Tutorial - Create Your First NFT (7)] Create an NFT DApp and assign attributes to your NFT, such as pictures
- Mysql CDC (2.1.1) inital snapshot database set up five concurrent degree, se
- MySQL使用简单教程
- 如何取得某月的最后一天
- 线程(上篇):线程的创建
- strongest brain (1)
- 十年架构五年生活-06 离职的冲动
猜你喜欢
随机推荐
`id` bigint(20) unsigned NOT NULL COMMENT 'Database primary key',
FPGA engineer interview questions collection 41~50
添加路由的2种方式--router
ThreadPoolExecutor线程池原理
summer preschool assignments
如何从代码层提高产品质量
RadiAnt DICOM Viewer 2022.1 Crack
如何模拟后台API调用场景,很细!
Consulting cdc 2.0 for mysql does not execute flush with read lock. How to ensure bin
Stacks and Queues | Valid parentheses, delete all adjacent elements in a string, reverse Polish expression evaluation, maximum sliding window, top K high frequency elements | leecode brush questions
二进制中负数为何要用补码形式来表示——二进制加减法
How does flinksql write that the value of redis has only the last field?
十年架构五年生活-07 年轻气盛的蜕变
JS gets the year, month, day, time, etc. of the simple current time
FPGA engineer interview questions collection 1~10
EasyGBS连接mysql数据库提示“can’t connect to mysql server”,该如何解决?
Thread.sleep, Thread.yield 作用解释
【静态代理】
mysql cdc (2.1.1)inital snapshot数据库的时候设置了5个并发度,se
咨询cdc 2.0 for mysql不执行flush with read lock.怎么保证bin