数据库中的去重操作(删除数据库中重复记录的SQL语句)主要有三种方法
(1)rowid方法
(2)group by 方法
(3)distinct方法
1、rowid方法
根据Oracle带的rowid属性,可以进行判断是否存在重复语句;
select a,b,max(rowid) from test
group by a,b;
delete from test t where rowid not in
(
select max(rowid) from test
group by a,b;
)
2、用group by方法
主要用于分组统计,一般都是使用在聚合函数中使用;
select t.name,count(name) from STUDENT t group by t.name having count(name) > 1;
3、用distinct方法
一般用于比较小的表进行去重,会过滤掉多余的重复记录,返回不重复的记录或字段;
select distinct t.name from STUDENT t;