Querying the max value of a column in SQLite For Android

If you just want the biggest value then you want the SQL equivalent of: SELECT MAX(price) FROM spendings.

I tend to use db.rawQuery(String sql, String[] selectionArgs), so it would be: db.rawQuery("SELECT MAX(price) FROM spendings", null).

But I think you could do this with db.query(DATABASE_TABLE, new String [] {"MAX(price)"}, null, null, null, null, null);. Though I haven't tested that.


Another way to get the column could be to set the query to the max of a particular column, for example:

db.query(DATABASE_TABLE, null, "price=(SELECT MAX(price))", null, null, null, null)

The cursor that returns will be the highest price row in the database.

Tags:

Sqlite

Android