sql案例:删除多条内容相同的数据,只保留一条
delete from t_delete_test t1 wheret1.name in (select t2.name from t_delete_test t2 group by t2.name having count(1)>1)and t1.id not in(select min(t3.id) from t_delete_test t3 group by t3.name having count(1)>1);
?
?
备注:
select t2.name from t_delete_test t2 group by t2.name having count(1)>1 //查询名字至少有一条相同的数据
select min(t3.id) from t_delete_test t3 group by t3.name having count(1)>1 //查询名字至少有一条的数据,并且只显示最小的主键号
?
?
?