#删除emp_no重复的记录,只保留最小的id对应的记录。
删除emp_no重复的记录,只保留最小的id对应的记录。
https://www.nowcoder.com/practice/3d92551a6f6d4f1ebde272d20872cf05
1.先根据emo_no分组,找出每个的最小id,形成表t1。
select * from (
select min(id)
from titles_test
group by emp_no
) as t1
2.再用删除语句delete删除id不在t1表中的数据
delete from titles_test
where id not in t1
delete from titles_test where id not in ( select * from ( select min(id) from titles_test group by emp_no ) as t1 )