mysql不允许子查询的同时删除原表数据

错误:

delete from titles_test
where id not in(
    select min(id) from titles_test group by emp_no
)

正确:给子查询表添加别名

delete from titles_test
where id not in(
select * from (
    select min(id) from titles_test group by emp_no
)a
)

https://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05?tpId=82&tags=&title=&difficulty=0&judgeStatus=0&rp=1

posted @ 2021-09-29 16:55  小茅屋  阅读(104)  评论(0)    收藏  举报