The method of extracting the article m to nth record with a SQL sentence

Source: Internet
Author: User

1-Remove the record from table M to nth: (not in version)
2
3 SELECT TOP n-m+1 *
4 from Table
5 WHERE (id not in (SELECT TOP m-1 ID from Table))
6
7
8--Remove the M-to-N record (exists version) from table tables
9
Ten SELECT TOP n-m+1 * from TABLE as a WHERE not Exists
One (SELECT * FROM (select Top m-1 * from TABLE ORDER by id) b Where b.id=a.id)
Order by ID
13
14
The--m is superscript, n is subscript, for example, take out the 8th to 12th record, m=8,n=12,table is the table name
16
+ Select Top n-m+1 * from Table
Where id> (Select Max (Id) from
(Select Top m-1 ID from Table Order by Id ASC) Temp)
Order by Id ASC

The method of extracting the article m to nth record with a SQL sentence

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.