How can I get the minimum value of an database column?
I need to find the minimum _id
of a SQLite table.
I tried the following, but had no success:
Cursor c = db.query(MY_DATABASE_TABLE_LAST_REQUEST, new String[] { "min(" + KEY_ROWID + ")" }, null, null,
null, null, null);
int rowID = c.getInt(0);
What am I doing wrong?
Make sure you call moveToFirst before getting the value:
Cursor c = db.query(MY_DATABASE_TABLE_LAST_REQUEST, new String[] { "min(" + KEY_ROWID + ")" }, null, null,
null, null, null);
c.moveToFirst(); //ADD THIS!
int rowID = c.getInt(0);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With