1. 程式人生 > >SQL針對單列刪除重複資料只保留一條id最大的資料

SQL針對單列刪除重複資料只保留一條id最大的資料

delete from t_student  where id in ( 
SELECT id from (
SELECT * from t_student  
where  name in (select name  from t_student where  name is NOT NULL   group by name      having count(name) > 1) 
and id not in (select max(id) from t_student where  name is NOT NULL  group by name  having count(name)>1) 
) t