MySQL Common basic operational Syntax (vi)--conditional query on data ordering and limiting the number of results "command line mode"

Source: Internet
Author: User
1. Use order by to sort the results of the query, ASC ascending, desc descending:

You can also specify more than one field name and sort order after the order by:

2. Limit the number of query results by using limit:

0, which represents the starting position of the query, can also be understood as the number of skipped, and 2 in the number of queries that need to be queried. There are 3 data in this table because the number of bars is limited to 2, so the actual result is only two. In addition, the initial position here is 0, actually can not write, the default is 0:

There is also a case where the number of specified query results may be greater than the actual number in the table, this time the return result will return all eligible data in the table, for example, there are 3 data in my table, if the specified number is 4, actually query out of 3:

The Where condition, order by sort, and limit can be used together, and many of the actual scenarios are used together:


MySQL Common basic operational Syntax (vi)--conditional query on data ordering and limiting the number of results "command line mode"

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.