Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to step through each entry in an SQLite index
    primarykey
    data
    text
    <p>I'm working on an SQLite DB Table that has fields "Given name", "Surname", and an index formed from (Surname, Given). The primary index is just an integer Name ID. I want to find the first Surname that starts with a search argument (a character string), </p> <pre><code>SELECT Given, Surname FROM NameTable WHERE Surname&gt;'C' LIMIT 1 </code></pre> <p>then either step forward or backward, one row at a time, through the Surname+Given index. I have read the SQLIte "Scrolling Cursor" <a href="http://www.sqlite.org/cvstrac/wiki?p=ScrollingCursor" rel="nofollow">article</a>, but that solution doesn't quite fit my program's structure. Saving the most recently retrieved Surname, then querying for Surnames that are less than this one, won't work because it might skip several names that precede the most recent name, but have the same surname.</p> <p>Since this is based on a simple index, it should be possible to step through the index. Is it possible to reference directly the ROWID of the index (not the table itself)? For example, assuming you have just retrieved the record corresponding to row 1234 of the index, and wish to go backward, how would you accomplish something like this:</p> <pre><code>SELECT Given, Surname FROM NameTable WHERE ROWID&lt;1234 (I realize this ROWID will refer to the table, not the index) </code></pre> <p>The table will contain entries such as:</p> <pre>SMITH, ABE SMITH, BARNEY SMITH, MARY SMITH, MIKE ...</pre> <p>I don't think I can use the prepare/step approach, because there could be many queries against the DB between scrolls.</p> <p>As an alternative, how does one make a search argument that concatenates Surname and Given? I could use that as a placeholder.</p> <p>Thanks in advance, and apologies for being an SQL newbie.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload