Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I try to run the following raw query in android, it seems not work

String query ="SELECT DISTINCT category FROM event";
Cursor  cursor = mDb.rawQuery(query, null);
if (cursor != null) {
     cursor.moveToFirst();
}
return cursor; 

so I decide to use the query() method in android which are something like

Cursor mCursor = mDb.query(EVENT_TABLE, new String[] {KEY_ROWID, KEY_CAT}, null, null,null,null, null)

Can anyone show me how to select the distinct category for using query() instead of rawquery please, any help will be greatly appreciated!

question from:https://stackoverflow.com/questions/11219361/select-distinct-value-in-android-sqlite

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use this method:

public Cursor query (boolean distinct, String table, 
                     String[] columns, String selection, 
                     String[] selectionArgs, String groupBy, 
                     String having, String orderBy, String limit)

Here first argument specifies whether to use distinct or not.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...