Paging query for Oracle, MYSQL, SQL Server, and DB2

Source: Internet
Author: User

Oracle, MYSQL, sqlserver, and DB2 paging queries DB2: www.2cto.com DB2 paging queries SELECT * FROM (Select Field 1, Field 2, Field 3, rownumber () over (ASC Column Used for order by sorting) AS rn from Table Name) AS a1 WHERE a1.rn BETWEEN 10 AND 20 or above indicates extracting the record from 10th to 20 select * from (select rownumber () over (order by id asc) as rowid from table where rowid <= endIndex) where rowid> startIndex if the Order By field has duplicate values, make sure to put this field in over () select * from (select ROW_NUMBER () OVER (order by DOC_UUID DESC) as rownum, DOC_UUID, DOC_DISPATCHORG, DOC_SIGNER, DOC_TITLE from DT_DOCUMENT) a where ROWNUM> 20 and ROWNUM <= 30 Add the row number, not sort select * from (select ROW_NUMBER () OVER () as rownum, t. * from DT_DOCUMENT t) a adds a row number and sorts BY column select * from (select ROW_NUMBER () OVER (order by DOC_UUID DESC) as rownum, t. * from DT_DOCUMENT t) a Mysql: the simplest select * from table limit start, pageNum, for example, getting 20 data from 10 select * from table limit 10, 20 Oracle: www.2cto.com select * from (select rownum, name from table where rownum <= endIndex) where rownum> startIndex example from table Sys_option (primary key is sys_id) the statement is as follows: SELECT * FROM (select rownum r, t1. * From Sys_option where rownum <30) t2 Where t2.R> = 10 SQL server: for example, to retrieve 10 or 20 records FROM the table Sys_option (primary key: sys_id), the statement is as follows: SELECT * From (select rownum r, t1. * FROM Sys_option where rownum <30) t2 Where t2.R> = 10
 

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.