SQL ascending and descending

Source: Internet
Author: User

"Select top 10 * from items ":

What does this mean? Is it equal to 1-10 records? The answer is "false", because top only queries the first 10 records in the data table. In general, top 10 records are arranged in order from 1 to 10, but sometimes it is not arranged in the order of search? Top 10 at this time

What may happen is:

ID name
1 aaa
2 bbb
5 CCCC
.
.
.

N ...... From the above, it is not necessarily from 1 to 10, and the ID is 3 or 4. It does not exist. It may be after 10th.

What if we want to follow the first 10 items from small to large: here we use the Ascending Order (ASC)

Use: Select top 10 * from items order by id asc. In this way, we can obtain records from 1 to 10.

Get new 10: Select top 10 * from items order by ID DESC

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.