1,你的数据库表中有主键,且主键上面的数据为唯一值。也就是没有重复值。
那么你在删除的时候,将这个唯一值作为条件进行删除。
如: delete from [表名] where id=1
2.所有的数据相同,那么你只能打开数据表,手工选定其中某一条,进行删除。
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条)