I am trying to fetch the last row from my SQLite database. Until now i have tried max,sql_sequence but nothing seems to work. I have to fetch the row values and assign it to a class variable. Any help is appreciated as I am new to SQLite and Android. Thanks..
If you have already got the cursor
, then this is how you may get the last record from cursor
:
cursor.moveToPosition(cursor.getCount() - 1);
then use cursor
to read values
or
do it like this
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToLast();
or
SELECT * FROM TABLE WHERE ID = (SELECT MAX(ID) FROM TABLE);
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