Sqlite MAX function - Grab the highest value

Asked

Viewed 372 times

2

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

This one, it’s like Long and keeps the date on milisegundos.

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

For that I 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 of this field?

1 answer

3


You can use the rawQuery() method that returns a Cursor, in which case you only have a field take index 0;

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

In my application I am using Count()

  • 1

    In my case, because it is a long use: cursor.getLong(0)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.