简体   繁体   中英

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM