MySQL Learning 2 Select

Source: Internet
Author: User

Select Limit Results

Cases

SELECT Prod_name

From Products

LIMIT 5;

The result is that only 5 results are given.

650) this.width=650; "title=" Tmp6a17 "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" tmp6a17 "src=" http://s3.51cto.com/wyfs02/M00/8D/CB/ Wkiom1iqwmdapzzraabjzkyiyfo945.png "" 325 "height=" 183 "/>

If you want to start from line fifth, the five elements

SELECT Prod_name

From Products

LIMIT 5.5;

~

LIMIT will retrieve the second row instead of the first row

~

LIMIT 10,5 but only 13 lines

Then MySQL will only return as many lines as he can return.

~

There is also the use of fully qualified table names

~

Sort Retrieve data

Select Prod_name

form Products;

The results are typically displayed in the order in which they appear in the underlying table, in the order that they were initially added to the table, and also affected by the MySQL reclaim storage space.

You can use the ORDER BY clause

Select Prod_name

Form Products

Order BY Prod_name; #将prod_name以字母顺序排序

Sort by multiple columns

Look at the following example, the first sort by prod_price, you can see the price sorted by

Appears 2 10.00, these two in alphabetical order according to Prod_name, Bird before, TNT in the back

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/8D/CB/ Wkiom1iqwmhsocq7aae3yeyaurc157.png "" 590 "height=" 422 "/>

Specify the sort direction

Select prod_id, Prod_price, Prod_name

Form Products

Order by Prod_price DESC; #其中DESC就是降序排列

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/8D/C8/ Wkiol1iqwmgar40raaf-6bonums708.png "" 482 "height=" 372 "/>

The above can be seen Prod_price is already descending row (from big to small)

In addition, you need to see if this column specifies a descending order, otherwise it's still coming.

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; border-bottom:0px; border-left:0px; Display:inline "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/8D/C8/wKioL1iqwmKBbi91AAHn1BY_ Yic139.png "" 533 "height=" 524 "/>

The opposite of DESC is ASC (ascending) but no egg, because the default is ascending

Example

Find the most expensive value in one table

Select Prod_price

Form Products

ORDER BY Prod_price DESC #降序排 the highest price will be on top

Limit 1; #只出来一个价格

MySQL Learning 2 Select

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.