假如有一张users表,里面有user_id,user_name两个字段,用一条sql语句去掉数据库里的userName重复的记录.
1.delete from users a where a.user_id = (select max(b.user_id) from users b where a.user_name=b.user_name);
这一种自联接,效率低一点.
2.delete from users where user_id not in(select max(user_id) from users group by user_name having count(user_name)>=1);
这一种先分组,效率高一些.
在此作下符号,希望对同行的朋友们有所启示.
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/songkexin/archive/2009/04/22/4099231.aspx