I want to get the last inserted row's primary key value which is set automatically(AUTO INCREMENT). I searched over the S/O and found answers for last row_id. But I need the last inserted row's values. Please help me.
Thanks
Try this code
String selectQuery = "SELECT * FROM " + "sqlite_sequence";
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToLast();
or
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE);
or
SELECT * FROM table ORDER BY column DESC LIMIT 1;
try this :
select * from <TABLE> where row_id = (select max(row_id) from <TABLE>);
or
SELECT * FROM tablename ORDER BY row_id DESC LIMIT 1;
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