Oracle, MYSQL, SQL Server data paging query

Source: Internet
Author: User

Paging Query for sqlserver2005

SQLSERVER2005 has been using the top keyword to achieve paged query, but inefficient, in the sqlserver2005 and later versions of the use of row_number () parsing function to complete the paging query, the efficiency has been greatly improved, but the SQL statement is more complex, The general formula for a paged query is given below:

/** firstindex: Start index * pageSize: Number per page * ordercolumn: Sorted field name * sql: can be a simple single-table query statement or a complex multi-table union query statement */select top pageSize o.* From (select Row_number () over (order by Ordercolumn) as rownumber,* from (SQL) as O where rownumber>firstindex;

  

Four ways of implementing SQL Server paging query

Oracle Paging Query

①rownum Query the general formula of the page:

/** firstindex: Start index * pageSize: Number per page * sql: Can be a simple single-table query statement or a complex multi-table union query statement */select * FROM (select A.*,rownum rn from (SQL) a where rownum<= (firstindex+pagesize)) where Rn>firstindex

②row_number () Analytic function paging Query general formula:

/* * FirstIndex: Start index * pageSize: Number per page * ordercolumn: Sorted field name * sql: can be a simple single-table query statement, or a complex multi-table union query statement */select * FROM (SELECT * F Rom (select T.*,row_number () over (order by Ordercolumn) as RowNumber from (SQL) t) p where p.rownumber>firstindex) where Rownum<=pagesize

  

Paged query for MySQL

MySQL paging query is the simplest, with the help of keyword limit can be implemented query, query statement general formula:

/** sql: Can be a single-table query statement, or can be a multi-table union query statement * FirstIndex: In fact, the index * PageSize: The number of records displayed per page */select o.* from (SQL) O limit firstindex, PageSize

  

Oracle, MYSQL, SQL Server data paging query

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.