日期:2014-05-17  浏览次数:20848 次

菜鸟问题(有关删除表内记录的问题...........高手进........)
现在小弟有一个表。。没有关键字,表中存有N表记录,有很多是相同的记录,想把相同的记录删掉(即保留相同记录中的一条,把重复记录删除)

高手请给个SQL语句。谢谢


急急急急

------解决方案--------------------
delete from table_name a
where rowid < (select max(rowid) from table_name
where column1=a.column1 and column2=a.column2
and colum3=a.colum3 and ...);

------解决方案--------------------
delete from stu where stuid in
(select stuid from stu group by stuid having count(*)> 1)
and rowid not in(select min(rowid) from stu group by stuid having count(*)> 1);
比如说stu表中有stuID字段和stuName字段
stuID字段有很多重复值

(select stuID from stu group by stuid having count(*)> 1)
查询出表中所有有重复的stuID

select min(rowid) from stu group by stuid having count(*)> 1
查询出表中所有要保留的stuID

------解决方案--------------------
我一般是 disticnt 然后 create 一个新表 把以前的备份 删除 再rename。

不过 根据rowid删除也不错的