delete tablename from tablename,(select username as kkk,max(user_id) as iid from tablename group by username having count(*)>1) b where tablename.username=b.kkk and tablename.user_id<b.iid
基本思想是用
select username as kkk,max(user_id) as iid from tablename group by username having count(*)>1 查找到最每一个最大的id号!
然后删除所有比它下的用户!
oracle 中可以如此
emp 表中删除重复的empno
delete from emp a
where exists(select b.empno from emp b where a.empno=b.empno
group by b.empno having count(*)>1)
and rowid not in (select min(rowid) from emp c where c.empno=a.empno);