Method of extracting the article m to nth record with an SQL statement

Source: Internet
Author: User

Original: The method of extracting article m to nth record with an SQL statement

  --Take the record of article M to nth from table tables: (not in version)

SELECT TOPN-m+1 *
from Table
WHERE(ID not inch (SELECT TOPm-1ID from Table ))

--Remove the M-to-N records from table tables (exists version)

SELECT TOPN-m+1 *  from TABLE  asaWHERE  not Exists
(Select *  from (Select Topm-1 *  from TABLE Order  byID) bWhereb.id=a.id)
Order  byID


--m is superscript, n is subscript, for example, take out 8th to 12th record, m=8,n=12,table is table name, TEMP is temp table

Select TopN-m+1 *  from Table
WhereId>(Select Max(Id) from
(Select Topm-1Id from Table Order  byIdASC) Temp)
Order  byIdASC

--The more awkward way to figure out the ascending m to nth record is

Select *  from
(Select TopN-m+1 *  from (Select TopN*  fromTable nameOrder  byIDDesc) T1Order  byID) T2
Order  byID

Method of extracting the article m to nth record with an SQL statement

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.