2

How can I select only one contact that is repeated in contacts list?

For example, if a user has a number (xxxx-xxxxxxx) two time in his contact list, I would like to select it only one time. In short, any method to pass GROUP BY NUMBER in query. I am using below method to select contacts:

Cursor contacts = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, " DISPLAY_NAME ASC");
peterh
  • 11,875
  • 18
  • 85
  • 108
Mubeen Ali
  • 2,150
  • 2
  • 18
  • 26
  • possible duplicate of [How to use the LIMIT argument in an SQLite Query with Android](http://stackoverflow.com/questions/6361668/how-to-use-the-limit-argument-in-an-sqlite-query-with-android) – Emile Sep 23 '14 at 12:49
  • no cant it `limit` means that select only `x` contacts. – Mubeen Ali Sep 23 '14 at 12:55
  • A valid point, though if your initial query is returning duplicate entries of the same contact, then either the question is "what" to differentiate on, or use limit if your happy that any (first) of the contacts would be valid, right? – Emile Sep 25 '14 at 16:04
  • @emile yes any first contact would be right but this answer is wrong because limit in query means select maximum "1, 2 or any integer that is defined for limit like `limit x` but I want to select all contacts but don't want to select any number two time if user has entered a number two times in contact lime – Mubeen Ali Sep 25 '14 at 18:07
  • Would the DISTINCT keyword help, http://www.w3schools.com/sql/sql_distinct.asp – Emile Sep 26 '14 at 09:13
  • I was thinking the same but but not sure how can we pass distinct in `ContactsContract.CommonDataKinds.Phone.CONTENT_URI` this – Mubeen Ali Sep 26 '14 at 13:27
  • on this page search Distinct, looks like its a boolean first paramter. http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html – Emile Sep 26 '14 at 13:58
  • Similar post here http://stackoverflow.com/questions/8787413/how-to-get-a-cursor-with-distinct-values-only – Emile Sep 26 '14 at 13:58
  • @Emile i understand distinct but can you tell me how can i use `DISTINCT` in my query i don't now how can i use so this is my question can you answer it? – Mubeen Ali Sep 26 '14 at 14:31

0 Answers0