Different database Oracle MySQL SQL Server DB2 infomix Sybase paging query statement

Source: Internet
Author: User
Tags sybase sybase database

Paged query statements that are used in different databases:

Current page: CurrentPage
Page Size: pagesize


1. Oracle Database

SELECT * FROM (select A.*,rownum rn from (query_sql) A) where Rn <= ((currentpage+1) *pagesize) and RN > (current Page*pagesize)

Note: query_sql is a query SQL statement.

Or

SELECT * FROM (select RowNum rn,id from TABLENAME where RowNum <= ((currentpage+1) *pagesize)) A where A.rn >= (cur Rentpage*pagesize)

2. Infomix Database

Select Skip CurrentPage First pagesize * from TABLENAME

3. DB2 Database

SELECT * FROM (select field 1, Field 2, Field 3,rownumber () over (order by sort with column name ASC) as RN from table name) as A1 where A1. RN between (Currentpage*pagesize) and ((currentpage+1) *pagesize)
Or
SELECT * FROM (select RowNumber () over (order by ID ASC) as ROWID from table where rowID <= ((currentpage+1) *pagesize)) where rowID > (currentpage*pagesize)


4. SQL Server Database

Select Top PageSize *
From TABLENAME
where Collumn_no not in
(select Top Currentpage*pagesize collumn_no from TABLENAME order by Collumn_no)
ORDER BY Collumn_no

5. Sybase database

Sybase 12.5. Version 3 supports top queries, or uses SET ROWCOUNT N to query header n data
A temporary table is also used:
Select Rowid=identity, column_name to #TEMPTABLE from TABLENAME
Select column_name from #TEMPTABLE where rowID > (currentpage*pagesize) and rowID < (currentpage*pagesize+pagesize)

6. mysql Database

SELECT * from TABLE1 LIMIT (currentpage*pagesize), pagesize

Different database Oracle MySQL SQL Server DB2 infomix Sybase paging query statement

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.