I have a database table with 3 columns: _id, name, groupName
It looks similar to this:
1 Tom group1
2 Sam group1
3 Ted group2
4 Jerry group3
5 Me group3
I want to query the database table for groupName. I have tried this:
public Cursor getAllGroups()
{
return db.query(DATABASE_TABLE_1, new String[] {KEY_GROUP},
null, null, null, null, null);
}
And this returns a cursor along: (group1, group1, group2, group3, group3).
Is there a way to get only unique groups? (So I would end up with a cursor along: (group1, group2, group3)
Thanks in advance.
解决方案
I think you need use raw SQL query with DISTINCT keyword. Rough code would be something like:
db.rawQuery("select distinct groupName from "+DATABASE_TABLE_1, null);