Use an SQL statement to retrieve records from the MTH to nth

Source: Internet
Author: User
Use an SQL statement to retrieve records from the m to n records -- retrieve records from the Table from the m to the n records: (NotIn Version) SELECTTOPn-m + 1 * FROMTableWHERE (idNOTIN (SELECTTOPm-1idFROMTable) -- extracts the m to n records (Exists version) from the TABLE SELECT

Use an SQL statement to retrieve records from the m to n records -- retrieve records from the Table from the m to the n records: (Not In version) select top n-M-1 + 1 * FROM Table WHERE

Retrieve records from the MTH to nth records using an SQL statement
-- Retrieve the records from the Table from entry m to entry n: (Not In version) select top n-m + 1 * FROM Table WHERE (id not in (select top S-1 id FROM Table) -- extracts records FROM the TABLE Table (Exists Version) select top n-m + 1 * from table as a WHERE Not Exists (Select * From (Select Top m-1 * From TABLE order by id) B Where B. id =. id) Order by id -- m is the superscript, and n is the subscript. For example, extract 8th to 12 records, m = 8, n = 12, and Table is the Table name, temp is the temporary Table 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 -- find the m to n records in ascending Order, the more clumsy way is to Select * From (Select Top n-m + 1 * From (Select Top n * From table name Order By id Desc) t1 Order By id) t2 Order By id

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.