Mysql查询某字段重复值并删除重复值
时间:2022-03-15 15:13
1.查询重复值:
select code,count(*) as count from hospital group by code having count>1;
该语句查询code重复值大于1的记录
2.删除重复:
DELETE FROM hospital WHERE id NOT IN (SELECT dt.minno FROM (SELECT MIN(id) AS minno FROM hospital GROUP BY code) dt);
该语句保留id最小的记录,其余code重复的记录全部删除