Actually there is an application for android. The database is connected. Is it possible to somehow get the id of the last element in the table?
2 answers
SELECT * FROM MYTABLE ORDER BY column DESC LIMIT 1; or
SELECT * FROM MYTABLE WHERE ID = (SELECT MAX(ID) FROM TABLE); or something like this:
String query = "SELECT ROWID from MYTABLE order by ROWID DESC limit 1"; Cursor c = db.rawQuery(query); if (c != null && c.moveToFirst()) { lastId = c.getLong(0); } - 2To get the ID is enough SELECT MAX (ID) FROM TABLE - Vladyslav Matviienko
|
In a relational database that is SQLite, there is no first / last concept. It all depends on how the query is sorted / indexed. Implicitly there is, of course, the ROWID field, but even it does not guarantee that the last one is supposed to be the last insertion.
And you can get the last entry in the current request (with some sort of output sorting) through:
Cursor cursor=db.rawQuery(query); //некий запрос сursor.moveToLast(); |