Paging query statements for MySQL, Oracle, and SQL Server

Source: Internet
Author: User

Original address: http://www.cnblogs.com/ginponson/p/5746435.html

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.

Paging Query for 1.Mysql

SELECT *  from  Student  -1* pagesize,pagesize;

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

Paging Query for 2.Oracel

 select  *   From   ( select   ROWNUM RN,  *  from student  where   Rownum  <=  pageno * pageSize)  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

 select  top  PageSize *  from   ( select   Row_number ()  over  (order  by  ID asc ) RowNumber, *  from student) A  where   A.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.

Paging 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.