How the database queries the second data with different IDs

Source: Internet
Author: User

about how the database queries the second data with different IDs

In the Sever 2008 database, the query statement is

SELECT * FROM table name or select column name from table name

This is to query all the data in a table, then query the second statement?

Start with "Top 2" can query the first two data, and then sorted according to the specified column name, so that you can

"SELECT top 2 * from table name order BY column name desc" (DESC reverse ACS positive sequence),

But the query out for the last two data, visible is the first reverse and then query the first two. Then the reverse is not feasible.

There are two data in the positive order, so that if one is removed, it is obvious that the first piece is taken out. First we have to find out,

"SELECT top 1 * FROM table name order BY column name ID" (positive order does not need to add ACS, itself is the positive order)

Then the ID of the data is removed, how to remove the "not in"

"SELECT * from table name where column name ID not in (SELECT Top 1 column name ID from table name Order by column name ID)"

So the data of the query does not exist the first data, now the second article becomes the first data. and "How the database queries the second data and the ID is different" is now the first data query.

"SELECT top 1 * from table name where column name ID not in (SELECT top 1 column name ID from table name Order by column name ID)"

How the database queries the second data with different IDs

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.