mysql 中update/delete语句的子查询改写

#update子查询(不支持)
update table_name q set q.level=2 where q.id in( select id from table_name where id>=2111 limit 165,165);

在这里插入图片描述

#update改成一下写法
update table_name q inner join ( select id from table_name where id>=2111 limit 165,165) t on q.id=t.id set q.level=2;

#delete子查询(不支持)
delete from table_name where id in (
select min(id) as id from table_name group by xxxx having count(1)>1
);

#delete改成一下写法
delete from table_name where id in (
select id from(
select min(id) as id from table_name group by xxxxx having count(1)>1
) t
);

你可能感兴趣的:(数据库)