"SELECT MAX(rowid) FROM table" query works only after "SELECT * FROM table" has been called
Have you tried using an order by and a limit? Something like
Select rowid as mr from surveys order by rowid desc limit 1
might work better for you.
If you want the maximum row ID from those in a range, you can execute the following:
SELECT MAX(rid) as mr FROM ( SELECT rowid as rid FROM surveys ORDER BY rowid LIMIT 10000 OFFSET 0)
How it Works
- The inner (parenthesised)
SELECT
gets the row IDs for the specific range. (TheOFFSET
of a limit dictates which row to start from, where the first row in a table is row 0. Think of it as how many rows to skip, from the start.) - The outer
SELECT
,SELECT MAX(rid)
, gets the maximum value from that range.