11qq 发表于 2011-4-13 15:15:06

如何在mysql删除相同文章

大家在采集过程中都会遇到过带有重复文章,请问有什么sql语句可以批量删除相同文章呢?

stick 发表于 2011-4-13 16:02:40

为神马不做入库前冗余检测

11qq 发表于 2011-4-13 16:05:45

原帖由 stick 于 2011-4-13 16:02 发表 http://hostloc.wiki/images/common/back.gif
为神马不做入库前冗余检测

不懂,我这个程序自动更新内容的,没有检测的

糕手 发表于 2011-4-13 16:31:28

11qq 发表于 2011-4-13 16:47:06

原帖由 糕手 于 2011-4-13 16:31 发表 http://hostloc.wiki/images/common/back.gif
查询相应表单,然后根据文章标题(这个重复文章看你定义是什么,一般定义是标题),查询,相同的 删除

我首先查询满足两个字段title和content,就被视为重复文章.

select * from piao_post a
where (a.title,a.content) in (select title,content from piao_post group by

title,content having count(*) > 1)

然后只保留pid最小值,但报错,语句我看了很多遍都没错啊.但就是报错.

delete from piao_post a
where (a.title,a.content) in (select title,content from piao_post group by

title,content having count(*) > 1)
and pid not in (select min(pid) from piao_post group by title,content having

count(*)>1)

[ 本帖最后由 11qq 于 2011-4-13 16:51 编辑 ]

a219549 发表于 2011-4-13 22:11:09

为什么不在插入数据库之前做检测呢,如果重复就不插入数据库

jacksoking 发表于 2011-4-14 00:47:49

如果采集的话,直接搞title就行了
你的表结构是如何?

美国主机商 发表于 2011-4-14 01:34:04

你的表是什么结构的
页: [1]
查看完整版本: 如何在mysql删除相同文章