1. 程式人生 > >表中重複資料去重只保留一份(id較小的)

表中重複資料去重只保留一份(id較小的)

查詢店員表w_other_empl中身份證號ss_id重複的數量

select t.ss_id,count(t.ss_id)  from w_other_empl t 
group by ss_id
having count(t.ss_id)>1
order by ss_id;

在這裡插入圖片描述

查詢店員表w_other_empl中身份證號ss_id重複的資料較小的id,並刪除id為其它的資料

delete from w_other_empl tt where tt.id not in(
select min(id) as t_id from w_other_empl t
group by ss_id
having count(t.ss_id)>1
);

在這裡插入圖片描述