Test data
In order to demonstrate this, some test data is necessary.
The table is filled with the numbers 0 through 9 and the respective english representation.
The table is not filled in any particualar order on purpose.
create table nums (
num integer,
txt text
);
insert into nums values (5, 'five' );
insert into nums values (9, 'nine' );
insert into nums values (7, 'seven' );
insert into nums values (1, 'one' );
insert into nums values (4, 'four' );
insert into nums values (8, 'eight' );
insert into nums values (0, 'zero' );
insert into nums values (2, 'two' );
insert into nums values (6, 'six' );
insert into nums values (3, 'three' );
Select the next 2 records (paging)
If the limit
clause is given two arguments, the first is interpreted as the start record and the second argument as the number of records that should be returned:
select
num,
txt
from
nums
order by
num
limit 4, 2 -- 4: Start record, 2: how many records
;
--
-- 4|four
-- 5|five
SQLite also understands the limit … offset
clause which is easier to read. The next query returns the same records:
select
num,
txt
from
nums
order by
num
limit 2
offset 4
;
--
-- 4|four
-- 5|five