views:

80

answers:

1

Hey, I'm trying to query the words which have the maximul values in the cont columns. Ex: if the word "test1" has the value 5 in cont, and "test2" has 2, "test1" will be shown in first position. got it?

so. Im trying to do it but it returns the following error:

09-18 22:24:04.072: ERROR/AndroidRuntime(435): Caused by: android.database.sqlite.SQLiteException: misuse of aggregate function MAX(): , while compiling: SELECT word FROM words WHERE MAX(cont) ORDER BY cont desc

Here is my method:

public List<String> selectMaxCont(){
   List<String> list = new ArrayList<String>();
   Cursor cursor = this.db.query(TABLE_NAME, new String[]{"word"}, "MAX(cont)", null, null, null, "cont desc");
   if(cursor.moveToFirst()){
       do{
   list.add(cursor.getString(0));
       }while(cursor.moveToNext());
   }
   if(cursor != null && !cursor.isClosed()){
       cursor.close();
   }
   return list;

}

+1  A: 

I think you are trying to descending sort by the column cont:

In that case, try this:

select * from words order by cont desc;

You shouldn't need max() to sort by a column.

FYI:

max() is an aggregate function and needs to be selected.

select max(column) from table

only returns one value.

select * from TABLE where COLUMN < (select max(COLUMN) from TABLE);

returns rows where the value in COLUMN is less than the max in that column.

magaio