MySQL报错1093 - You can't specify target table 't' for update in FROM clause, Time: 0

2023-10-11 14:46:50 浏览数 (3)

报错内容:

1093 - You can't specify target table 't' for update in FROM clause, Time: 0

前情提示:

Mac OS10.14 MySQL8.0.18;

centOS6.8final MySQL5.6;

解决:

方法一:多嵌套一层。多来一层子查询

以上SQL修改如下:

代码语言:javascript复制
UPDATE trace_videorecord SET VideoAddress = 'h8' WHERE VideoID IN
(
SELECT * FROM (
SELECT mg.VideoID FROM sale_goods m LEFT JOIN  prod_task md ON m.TaskID = md.TaskID  LEFT JOIN prod_area ma on md.AreaID = ma.AreaID LEFT JOIN acct_factory mb ON ma.FactoryID = mb.FactoryID  LEFT JOIN trace_videorecord mg ON ma.AreaID = mg.AreaID WHERE m.GoodsID = '128' and mg.Status=1 ORDER BY mg.AddTime DESC LIMIT 0,30
)a
)

方法二:中间表,临时表。

代码语言:javascript复制
1.创建一张临时表,将要删除的条件自动存入临时表中:
2.再根据临时表,删除主表数据:
3.最后删除掉临时表:
create table tmp as select min(id) as a from user group by additive;
delete from user where id not in (select a from tmp);
drop table tmp;

0 人点赞