0

Can anyone help me how to execute this query?

I am trying to fetch distinct supervisor from project table. supervisor is column name and its index is 5.

try {

String query = "select distinct supervisor from project ";
            Cursor cursor= db.rawQuery(query,null);//query( query , null, null,null,null,null,null);

            if (cursor.moveToFirst()) {
                do {
                    labels.add(cursor.getString(5));
                } while (cursor.moveToNext());
            }

           // finish();
           cursor.close();
           db.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return labels;
    }

enter image description here

2 Answers2

0

Your query is wrong.

You have to query write like this.

select * from project where YOUR_CONDITION

I don't know what you exactly trying to do.

Example query.

select * from customers where LastName = 'Tremblay'

To get Distinct value of supervisor you should query like this.

select * from project group by supervisor 

Hope it helps:)

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
-1

You could use an if statement ie if cursor != null, do something.

Joshua
  • 589
  • 1
  • 5
  • 19