SQL语句的查询和插入(更新)嵌套技巧([HY000][1093] You can’t specify target table ‘xxx’ for update in FROM clause)
这个报错是说同一个表的查询结果不能再放入同一个表的更新操作,包括插入操作也是一样的。
解决方法也很简单,就是让它以为我们所查询的数据并不是从同一个表里面得到的,
原代码:
insert into 表名 (tb_id,tb_name,tb_list)
value (null,'hfhua',
(select max(tb_list) from 表名 where tb_id = 1) );
正确示范:
insert into 表名 (tb_id,tb_name,tb_list)
value (null,'hfhua',
(select a.xx from
(select max(tb_list) xx from 表名 where tb_id = 1) as a
) );
还是挺简单的,就是通过取别名虚构表蒙混过关,懒得分开写两次那就先这样咯。