How to get a cursor with only individual values?

I want to return a cursor with only individual column values. There are more items in the Groups column, but with only two values: 1,2,1,1,1,2,2,2,2

String[] FROM = {Groups,_ID}; public Cursor getGroups(){ //...... return db.query(TABLE_NAME,FROM,null,null,null,null,null); } 

will return a cursor containing {1,2,1,1,1,2,2,2,2,1,1}, but I would just like to specify {1,2}.

+4
source share
4 answers

You might have a sql query like this

 public Cursor usingDistinct(String column_name) { return db.rawQuery("select DISTINCT "+column_name+" from "+TBL_NAME, null); } 
+8
source

you can use various arguments when creating a query as follows:

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

Follow this doc for more clarity.

+5
source

You can use the sample query below, since you need to specify a column name for different

 Cursor cursor = db.query(true, YOUR_TABLE_NAME, new String[] { COLUMN_NAME_1 ,COLUMN_NAME_2, COLUMN_NAME_3 }, null, null, COLUMN_NAME_2, null, null, null); 

COLUMN_NAME_2 is the column name for the individual.

don't forget to add GROUP BY column names

0
source

Use boolean true in a separate argument, for example:

 public Cursor query (**true**, String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit); 
0
source

Source: https://habr.com/ru/post/1390024/


All Articles