MySQL implementation of paged query Sql,mysql implementation of the SQL statement of paged query (GO)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.