msyql进行更新操作遇到的问题

发布时间:2024年01月10日

msyql进行更新操作遇到的问题

1. You can’t specify target table ‘xxx’ for update in FROM clause

1093 - You can’t specify target table ‘xxx’ for update in FROM clause

update table_a set type = 3 where id in (select id from table_b where xxx=8) ;

table_a和table_b不是同一张表不会报错

update table_a set type = 3 where id in (select id from table_a where xxx=8) ;

如果是同一张表就会报错
在这里插入图片描述
解决办法就是多包一层


update table_a  set  type = 3   where id in (select id from  (select id from table_a  where  type =8)  as tmp );

语句的意思就是把type 3 的改为type 8

2 使用update语句时候set使用and拼接引发的数据错误
在这里插入图片描述
将type1改为 9 type2改为3

在这里插入图片描述
在这里插入图片描述
然后会发现。type1变成了0,type2 变成了1
如果小白第一次执行这样的语句又没有经验,又在重要的环境,又不懂得提前备份的习惯,岂不是要引发大问题

在这里插入图片描述
将数据还原使用逗号 , 进行拼接才对

在这里插入图片描述

文章来源:https://blog.csdn.net/ganjiee0007/article/details/135497508
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。