Paging query statements for MySQL, Oracle, and SQL Server

Source: Internet
Author: User

Assuming that this is page pageno, there are pagesize records per page, and now the student table is queried using MySQL, Oracle, and SQL Server paging.

1. mysql Paging query:

1 SELECT 2     * 3  from 4     student5-1* pagesize,pagesize;

Understanding: (Limit n,m) + starts from the nth line to fetch M Records, n from 0 to calculate.

2, Oracel paged query:

1 SELECT2     *3  from4     (5         SELECT6ROWNUM RN,*7          from8 Student9         WHERETenRownum<=PageNo*pageSize One     ) A WHERE -Rn>(PageNo- 1)*PageSize

Understanding: Suppose PageNo = 1,pagesize = 10, first take the row number less than or equal to 10 from the student table, and then remove the RN greater than 0 records from these records, so as to achieve paging purposes. RowNum starting from 1.

3. SQL Server Paging query:

1 SELECT2     TOPPageSize*3  from4     (5         SELECT6Row_number () Over(ORDER  byIdASC) RowNumber,*7          from8 Student9 ) ATen WHERE OneA.rownumber>(PageNo- 1)*PageSize

Understanding: Suppose PageNo = 1,pagesize = 10, sort by the ID of the student table first, rownumber as the line number, and then take out 10 records starting at line 1th.

Paged query Some of the database may have several ways, here may not be the most efficient way to query, but this is the most convenient paging query I use, if interested can also be used in other paged query the way to study.

Paged query statements for MySQL, Oracle, and SQL Server

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.