删除表中重复记录,只保留一条:

delete from 表名 where 字段ID in (select * from (select max(字段ID) from 表名 group by 重复的字段 having count(重复的字段) > 1) as b);

实例:
2.当想要为某一个表建立一个唯一索引,由于表中有重复记录而无法进行时,需要删除重复记录。
例表 dept
id_no id_name
100 'AAA'
101 'BBB'
102 'CCC'
103 'DDD'
100 'EEE'
100 'FFF'
103 'GGG'
请写一条(或一组)SQL语句,删除重复的行,但重复的行中需要保留一行,
如上表,id_no=100需要删除2行,保留一行,id_no=101需要删除一行保留一行id_no=102和103则不删

[color=violet]delete from dept where id_no not in ( select * from (select max(id_no) from dept group by id_no having count(id_no)>1) b);[/color]