MySQL Limit paging

Source: Internet
Author: User

There are two ways to use limit for paging in MySQL

Example 1, suppose that there are 13 data in the database table student.

code example:
Statement 1:select * FROM student limit 9,4
Statement 2:slect * FROM student limit 4 offset 9
Statements 1 and 2 return rows 10th, 11, 12, and 13 of table student, the first parameter represents the beginning of the next data in the parameter, and the second parameter represents the number of data bars returned each time.
4 in Statement 2 returns 4 rows, 9 means starting from row tenth of the table

Example 2, the paging function can be achieved by limit and offset or by limit only.
Assuming that pagesize represents the number of bars to display per page, pagenumber represents the page number, then return to page pagenumber, the SQL statement with the number of pagesize per page:

code example:
Statement 3:select * FROM studnet limit (pageNumber-1) *pagesize,pagesize
Statement 4:select * FROM student limit pageSize offset (pageNumber-1) *pagesize

Calculate pagesize and offset in Java

   The number of bars displayed per page, as an interface parameter passed in
int pageSize = 10;
Total number of bars, querying from the database
int totalcount;
//Total pages Double tp= count/(double) pageSize; int totalpage = (int) Math.ceil (TP); int offset = (page-1) * pageSize;

MySQL Limit paging

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.