Reputation: 6377
I'm unable to write select-where-unique query for my database. I have managed to query my db using where clause by using:
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_KEYWORD},
KEY_TIME + "=" + strtime,
null,
null,
null,
null,
null);
How can I insert "DISTINCT" keyword for column KEY_KEYWORD?
Upvotes: 1
Views: 5924
Reputation: 6377
Following worked for me:
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_KEYWORD},
KEY_TIME + "=" + strtime,
null,
null,
null,
null,
null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
Thanx Desiderio and lucho for trying to help.
Upvotes: 4
Reputation: 12021
A possible solution to your problem is to use the class SQLiteQueryBuilder.
Example:
Query: SELECT DISTINCT A.x FROM A,B WHERE A.ID = B.ID
SQLiteQueryBuilder sqLiteQueryBuilder = new SQLiteQueryBuilder();
sqLiteQueryBuilder.setTables("A, B");
sqLiteQueryBuilder.setDistinct(true);
String selection = "A.ID = B.ID";
Cursor c = sqLiteQueryBuilder.query(db,
new String[]{"A.x"},
selection,
null,
null,
null,
null);
Cheers!
Upvotes: 0
Reputation: 11028
Please try this:
Cursor mCursor =
db.query(true, DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_KEYWORD},
null,
null,
KEY_KEYWORD,
null,
null,
null);
and let me know if that works.
Upvotes: 2