http://blog.csdn.net/sxdtzhaoxinguo/article/details/51481430
Abstract: MySQL database implementation of paged query SQL statement writing!
One: Paging needs:
The client passes the start (page number), limit (number of bars per page) two parameters to page through the data in the database table, then we know that the MySQL database provides paging function limit m,n, but the use of this function is different from our needs, So we need to adapt to the actual situation to rewrite the appropriate page for our own statement, the specific analysis is as follows:
Like what:
The SQL for querying data 1th through 10th is: SELECT * FROM table limit 0, 10; We need to query the first page of data: SELECT * FROM table limit (1-1) *10,10;
The SQL for querying data 10th through 20th is: SELECT * FROM table limit 10, 20; We need to query the second page of data: SELECT * FROM table limit (2-1) *10,10;
The SQL for querying data 20th through 30th is: SELECT * FROM table limit 20, 30; We need to query the third page of data: SELECT * FROM table limit (3-1) *10,10;
Second: Through the above analysis, we can get to meet our own needs of the paging SQL format is: SELECT * FROM table limit (start-1) *limit,limit; Where start is the page number, limit is the number of bars displayed per page.
MySQL implementation of paged query Sql,mysql implementation of the SQL statement of paged query (GO)