msyql进行更新操作遇到的问题
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
如果小白第一次执行这样的语句又没有经验,又在重要的环境,又不懂得提前备份的习惯,岂不是要引发大问题
将数据还原使用逗号 ,
进行拼接才对