Brannon King wrote:
select rowid from table limit 1 offset -1;
Two ways to do this:
SELECT rowid FROM table ORDER BY rowid DESC LIMIT 1;
SELECT max(rowid) FROM table;
Yes, but neither one of those would be as fast as this query, true?
SELECT rowid FROM table LIMIT 1
I guess I was thinking to avoid the sort overhead.
Brannon,
The rowid column is the key field for the btree that stores the table
data. It is effectively always indexed. So neither of the queries
suggested by Richard will do any sorting. They will use the ordering
provided by this index to directly select the maximum value of the rowid
column, or the rowid of the last column in the table in rowid order
(which is the same thing). These queries will locate the last record in
O(log N) time using the rowid btree.
HTH
Dennis Cote