如何删除一个表中的内容只留其中一条?

来源:百度知道 编辑:UC知道 时间:2024/06/17 23:58:35
我的网站,采集时不小心采集了很多内容相同的文章.现在我想删除多余的,只留其中一条.这个SQL语句怎么写.MYSQL的数据库,表名comtent,字段名:title

1 楼JafyLiu(自由的代价)回复于 2005-02-01 16:22:08 得分 1delete from table where id in
( select distinct id from table group by id having count(id) > 1)

Top

2 楼xluzhong(Ralph)回复于 2005-02-01 16:37:44 得分 5如果有id
delete from tablename a where exists(select * from tablename where a.id<id and a.col1=col1)
如果没有id
alter table tablename add id int identity(1,1)
delete from tablename a where exists(select * from tablename where a.id<id and a.col1=col1)
alter table drop cloumn id
Top

3 楼hsj20041004(光芒)回复于 2005-02-01 17:02:29 得分 0 JafyLiu(土豆) ( ) 的不对,那不是把所有重复的记录都删除了!!!
Top

4 楼Qihua_wu(小吴)回复于 2005-02-01 17:11:12 得分 5alter table tablename add id int identity(1,1)

delete from tablename a where exists (select * from tablename