Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching last row from sqlite database

Tags:

android

sqlite

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..

like image 562
user2574903 Avatar asked Jul 16 '13 02:07

user2574903


1 Answers

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);
like image 157
Shakeeb Ayaz Avatar answered Oct 18 '22 07:10

Shakeeb Ayaz