According to the docs rowid is not guaranteed to be monotonic.

So this is not guaranteed to give the right answer.

SELECT ... ORDER BY rowid DESC LIMIT 1

However, define your own autoincrement (myid) and it is.

SELECT ... ORDER BY myid DESC LIMIT 1




Michael D. Black

Senior Scientist

NG Information Systems

Advanced Analytics Directorate



________________________________
From: [email protected] [[email protected]] on 
behalf of Simon Slavin [[email protected]]
Sent: Monday, August 22, 2011 2:49 PM
To: General Discussion of SQLite Database
Subject: EXT :Re: [sqlite] Last record in db


On 22 Aug 2011, at 8:43pm, Black, Michael (IS) wrote:

> I thought we were answering the question "how can I retrive the last row" -- 
> though we never got a definition of what "last" meant. [snip]

which is, of course, the problem with that question.

> Don't you agree that using autoincrement properly guarantees retrieving the 
> last inserted row?

As long as you're not messing about with the way SQLite does things, using the

SELECT ... ORDER BY rowid DESC LIMIT 1

form is as good an answer as any.

By the way, I don't think anyone has mentioned either

SELECT last_insert_rowid() FROM myTable

or the

sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*)

C function yet.

Simon.

_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to