Ekra
Ekra

Reputation: 3301

Sqlite Query select statement with sorted result respecting the OFFSET

I want to make a sqlite query in such a way that the result should be sorted which has a LIMIT and the OFFSET. But the OFFSET should work in synch a manner that it should discard the last records from the result.

SELECT * FROM TempTable WHERE CLASS = 1 ORDER BY Date ASC LIMIT 100 OFFSET 5;

The above query just ignores the first 5 records from the table and give the remaining records. But instead I want it to ignore the first 5 latest entries.

Note:- the first 5 latest entries means since I am sorting it by date it should IGNORE the latest record inserted in the table respecting the date.

Upvotes: 0

Views: 119

Answers (1)

LS_ᴅᴇᴠ
LS_ᴅᴇᴠ

Reputation: 11181

Sort backwards, with OFFSET 5 and resort again:

SELECT * FROM (
   SELECT * FROM TempTable WHERE CLASS = 1 ORDER BY Date DESC LIMIT 100 OFFSET 5
) ORDER BY Date ASC;

Upvotes: 2

Related Questions