Query regarding ACS pagination - limit and skip

You must Login before you can answer or comment on any questions.

I am confused with the pagination variables limit and skip. My question is if we use skip, for eg. limit=50 and skip=20, then will 20 entries be skipped from the 50 entry limit or the response will contain 50 entries but they will be after the 20 first entries (depending on the order clause)?

1 Answer

Accepted Answer

Some basic Different between LIMIT and SKIP keywords.
LIMIT <skip>, <count>  is equivalent to: LIMIT <count> OFFSET <skip>
i.e
Case 1 :  LIMIT <skip>, <count>
select * from tableDemo LIMIT 3,10 
Output :  Total we have 10 records in tableDemo . in which we are skip first 3 records [ Skiping recordes ascending order ] . 
 
if we are try out with 
 
select * from tableDemo order by id desc LIMIT 3,10 
Output : Total we have 10 records in tableDemo . in which we are skip first 3 records with order by descending cluse so we are skiping    last  3 records , in our case (8,9,10 ) id's 
 
Case 2 : LIMIT <count> OFFSET <skip>
 
select * from tableDemo  LIMIT 10 OFFSET 1
![alt Ascending Order ](/acs_order.png "Acending order LIMIT <skip>, <count> ") ![alt Descending Order ](/desc_order.png "Decending order LIMIT <skip>, <count> ")

same output for Case 2 , just syntax different.

— answered 8 months ago by Dipesh Jade
answer permalink
3 Comments
  • Suppose tabledemo contains 13 records {1,2,3...,13}, then by case 1, LIMIT 3,10 will return {4,5,...13}... Is that correct?

    — commented 8 months ago by Ammar Githam

  • Yes it is correct one. [ try this ]
     
    CREATE TABLE "tableDemo" ("id" INTEGER PRIMARY KEY  NOT NULL , "name" INTEGER)
     
    insert into tableDemo(name) values(1);
    insert into tableDemo(name) values(2);
    insert into tableDemo(name) values(3);
    insert into tableDemo(name) values(4);
    insert into tableDemo(name) values(5);
    insert into tableDemo(name) values(6);
    insert into tableDemo(name) values(7);
    insert into tableDemo(name) values(8)
    insert into tableDemo(name) values(9);
    insert into tableDemo(name) values(10);
     
    *******************************************************************
    select * from tableDemo LIMIT 3,10     
     
    Out put :
    Id           name
    "4"         "4"
    "5"         "5"
    "6"         "6"
    "7"             "7"
    "8"             "8"
    "9"               "9"
    "10"               "10"
     
    -------------------------------------------------------------
     
    select * from tableDemo order by id desc LIMIT 3,10
    Out put :
     
    Id              name
    "7"             "7"
    "6"             "6"
    "5"             "5"
    "4"             "4"
    "3"              "3"
    "2"             "2"
    "1"             "1"

    — commented 8 months ago by Dipesh Jade

  • Thank You So Much...!!!

    — commented 8 months ago by Ammar Githam

Your Answer

Think you can help? Login to answer this question!