首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

sql案例:剔除多条内容相同的数据,只保留一条

2013-07-09 
sql案例:删除多条内容相同的数据,只保留一条delete from t_delete_test t1 wheret1.name in (select t2.na

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 //查询名字至少有一条的数据,并且只显示最小的主键号

?

?

?

热点排行