查找、刪除多個字段相同的記錄

--查找姓名、性別、年齡、地址、電話相同的員工記錄。select

select count(id) as id_count,
name,
sex,
birthday,
address,
tel
from staff
group by name,
sex,
birthday,
address,
tel
having(count(*) > 1);vi

 

--刪除姓名、性別、年齡、地址、電話相同的重複員工記錄(保留ID最大的一條)。co

delete staff where id not in (select max(id) from staff group by name, sex, birthday, address, tel);let

相關文章
相關標籤/搜索