正确例子:
delete from `bbs_reply` where parent_id
in (select e.reply_id from
(select * from `bbs_reply` where parent_id=#{id} and reply_type=1) e)
and reply_type=2
报错1:
这是因为每个子查询查出来的表必须拥有自己的名字,加上便可。
报错2:
报错信息:You are using safe update mode and you tried to update a table without …
这是因为MySQL在保护模式, 无法进行批量删除
可以通过以下SQL进行状态查询:
showvariables like 'sql_safe%';
解决方案:
执行SQL:
set sql_safe_updates=0;
或
set sql_safe_updates=off;
报错3:
错误信息:You can’t specify target table ‘表名’ for update in FROM clause
它的意思是说,不能先select出同一表中的某些值,再update这个表(在同一语句中),即不能依据某字段值做判断再来更新某字段的值。
解决方案:将SELECT出的结果再通过中间表SELECT一遍,如上边示例
参考博客:https://blog.youkuaiyun.com/sanpic/article/details/79879408