删除重复的SQLite项 [英] Delete duplicates entries in SQLite

查看:208
本文介绍了删除重复的SQLite项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有重复的条目一个表。以外的primary_key所有条目都相同。

I have one table with duplicate entries. Other than the primary_key all the entries are the same.

中的条目甚至存储一个唯一的ID将是相同的,如果条目是重复的(secondID)。

The entries even stores a unique id that will be the same if the entries are duplicates (secondID).

即使它似乎并不难,我有想出一个rawQuery在Android的基础上,第二次的ID删除重复项的麻烦。

Even if it does not seem hard I'm having trouble coming up with a rawQuery in Android that delete duplicate entries based on the second id.

dataBase.rawQuery("DELETE FROM " + table + " WHERE " + secondID + " EQUALS " + secondID + ");", null);

我可能完全错了这个查询,但好像我已经尝​​试了一些非常复杂的查询和一些非常简单的像没有运气上面的那个。

I'm probably quite wrong about this query but seems like I've tried some really complicated queries and some really simple like the one above with no luck.

任何帮助将是AP preciated。

Any help would be appreciated.

推荐答案

或者是这样的:

DELETE FROM table WHERE primary_key NOT IN (SELECT MIN(primary_key) FROM table GROUP BY secondID)

这应该选择每个不同的secondID的第一个实例的主键,删除一切,是不是在该列表中。

Which should pick the primary key of the first instance of every distinct secondID, and delete everything that isn't in that list.

这篇关于删除重复的SQLite项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆