当前位置:首页 > CMS教程 > 帝国cms > 列表

自动删除新闻模型重复数据 并保留最后一条 帝国CMS V7.0

发布:smiling 来源: PHP粉丝网  添加日期:2014-11-14 10:54:36 浏览: 评论:0 

delete phome_ecms_news from phome_ecms_news, (select id from phome_ecms_news group by title having count(*)>1 ) as t2 where phome_ecms_news.id=t2.id

执行完成以上命令,还要执行一下 下面的语句来修正 副表.

delete from 'phome_ecms_news_index' where id not in(select id from phome_ecms_news)//开源软件:phpfensi.com

以上命令执行完即可,也可以用以下的命令修正副表 ID 错误,用以下命令进入 PHPMYADMIN 管理多于的错误 ID:

SELECT id FROM phome_ecms_news_data_1 WHERE NOT EXISTS (SELECT null FROM phome_ecms_news WHERE phome_ecms_news.id = phome_ecms_news_data_1.id);

 
 
 
 
 
解释:
delete 表 from 表, (select id from 表 group by 重复字段名 having count(*)>1 ) as t2 where 表.id=t2.id

Tags: 帝国CMS新闻模型 帝国重复数据

分享到: