where id not in(
select * from (select max(id) from zhszty_ebook group by url
) as tmp)------------mysql有个特性,对于表进行修改,删除 *** 作,子查询不能和外层的查询的表一样,所以在加个select就可以了。其他数据库按照楼上的那个是没问题的
1. 查询需要删除的记录,会保留一条记录。select a.id,a.subject,a.RECEIVER from test1 a left join (select c.subject,c.RECEIVER ,max(c.id) as bid from test1 c where status=0 GROUP BY RECEIVER,SUBJECT having count(1) >1) b on a.id<b.bid where a.subject=b.subject and a.RECEIVER = b.RECEIVER and a.id <b.bid
2. 删除重复记录,只保留一条记录。注意,subject,RECEIVER 要索引,否则会很慢的。
delete a from test1 a, (select c.subject,c.RECEIVER ,max(c.id) as bid from test1 c where status=0 GROUP BY RECEIVER,SUBJECT having count(1) >1) b where a.subject=b.subject and a.RECEIVER = b.RECEIVER and a.id <b.bid
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)