If performance of the query is a concern than add an additional field for 
keeping the "next" and update it with insert/delete triggers.  .
 
 
 
Michael D. Black
Senior Scientist
Advanced Analytics Directorate
Northrop Grumman Information Systems
 

________________________________

From: sqlite-users-boun...@sqlite.org on behalf of Igor Tandetnik
Sent: Tue 9/28/2010 6:41 AM
To: sqlite-users@sqlite.org
Subject: EXTERNAL:Re: [sqlite] Getting the next row



Cory Nelson <phro...@gmail.com> wrote:
> On Tue, Sep 28, 2010 at 3:32 AM, Ian Hardingham <i...@omroth.com> wrote:
>> If I have a table with a PRIMARY KEY AUTOINCREMENT id column, and I have
>> an id for a row, is there an Order(1) method of selecting the next row?
>>
>> I can't necessarilly guarantee that id + 1 exists, as it may be deleted.
>
> Try WHERE id>previousid ORDER BY id LIMIT 1.

Note that this is O(log N), not O(1). There is no O(1) method to do this (or 
pretty much anything else in SQLite), to my knowledge.
--
Igor Tandetnik

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to