SQlite MAX function - Get the highest value

2

I have Sqlite a field called date_start , which keeps the date of a walk.

This is of type Long and stores the date in milisegundos .

I would like, through a query, to return the highest value (the last recorded hike).

For this I have tried the following:

Cursor cursor = dataBase.query(table, properties, "MAX(date_start)", null,null, null, null, null);

But the following error occurs:

  

android.database.sqlite.SQLiteException: misuse of aggregate function   MAX () (code 1)

How do I get the highest value in this field?

    
asked by anonymous 06.06.2016 / 21:19

1 answer

3

You can use the rawQuery () method to return a Cursor, and in this case only one field gets the index 0;

Cursor cursor = db.rawQuery("select MAX(date_start) from Nometabela", null);
cursor.cursor.getString(0);

In my application I'm using count ()

    
06.06.2016 / 21:28