关于查询、删除重复记录的SQL操作

1,group by方法

查数据:

  

select count(num), max(name) from student --列出重复的记录数,并列出他的name属性 
  group by num 
  
having count(num) >1 --按num分组后找出表中num列重复,即出现次数大于一次 


删数据:
  

1 delete from student 
2   group by num 
3   having count(num) >1

  这样的话就把所有重复的都删除了。


2,用distinct方法 -对于小的表比较有用

1 create table table_new as  select distinct *  from table1 minux 
2 truncate table table1;
3 insert into table1 select * from table_new;




 

posted @ 2011-04-12 10:32  Code & Life  阅读(391)  评论(0编辑  收藏  举报