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

Arun Vinoth - MVP
  • 21,521
  • 14
  • 57
  • 157

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
  • 12,555
  • 11
  • 37
  • 63
-1

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

Joshua
  • 491
  • 4
  • 15