Write out an SQL statement: Take the 31st to 40th record in table A (SQL Server, with an auto-growing ID as the primary key, note: The ID may not be contiguous

Source: Internet
Author: User

Http://blog.sina.com.cn/s/blog_a342ff0a0101u3kb.html

SQL Server:

Solution 1:select Top * from a where ID not in (select top with ID from a);

Solution 2:select Top * from a Where ID > (select MAX (ID) from (select top with ID from a) as A);

As I understand it,

The first method: first 30 data (the default positive order) is queried based on the ID, and then the first 10 data in the 30 data is queried in the positive order.

The second method: first, according to the ID positive sequence query the top 30 data, the ID of the largest data ID, and then query Id>max (ID), that is, to obtain the data to be queried.

Write out an SQL statement: Take the 31st to 40th record in table A (SQL Server, with an auto-growing ID as the primary key, note: The ID may not be contiguous

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.