Use LIMIT to paginate results in MySQL query

前端 未结 3 902
迷失自我
迷失自我 2020-12-10 17:05

I want to fetch my results a \'page\' at a time; I want the page number to be a parameter (in a JDBC prepared statement). Consider the following snippet

SELE         


        
3条回答
  •  忘掉有多难
    2020-12-10 17:37

    Define Offset for the query using the following syntax

    SELECT column FROM table 
    LIMIT {someLimit} OFFSET {someOffset};
    

    For example, to get page #1 (records 1-10), set the offset to 0 and the limit to 10;

    SELECT column FROM table 
    LIMIT 10 OFFSET 0;
    

    To get page #2 (records 11-20), set the offset to 10 where the limit to 10

    SELECT column FROM table 
    LIMIT 10 OFFSET 10;
    

提交回复
热议问题