sql236
删除emp_no重复的记录,只保留最小的id对应的记录。
https://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05
delete from
titles_test
where
titles_test.id not in (
select
t.minid
from
(
select
min(id) minid
from
titles_test
group by
emp_no
) as t
)
知识点 delete + where 可删除指定行
但要遵循mysql运行逻辑,假设要更新的表是A,不可以引用A的元素来更新A。
否则会报错:You can't specify target table 'CUP_TEST_CLASS_LIST' for update in FROM clause
解决方法:利用子查询创立一个派生表过渡即可
查看2道真题和解析