abrsh
abrsh

Reputation: 525

How to query last inserted row in database sqflite

I wanted to get last row from database. I have come to realize there is only rawQuery on the documentation.

db.rawQuery("SELECT * FROM $tableName WHERE id=?', []");

So how do i manipulate the above query to fetch last row by id?

Upvotes: 1

Views: 1833

Answers (2)

Ayub Alam
Ayub Alam

Reputation: 1

try this one:

_db.rawQuery("SELECT max(id) FROM $tableName");

Upvotes: 0

Rishi
Rishi

Reputation: 41

Try something like this, assuming you have self-incrementing field:

db.rawQuery("SELECT * FROM $tableName WHERE id=(SELECT max(id) FROM $tableName, []" );

Upvotes: 3

Related Questions