SQLORDERBY statement usage-mysql tutorial

Source: Internet
Author: User
The ORDERBY statement is used to sort the result set. The ORDERBY statement is used to sort the result set based on the specified column. By default, the ORDERBY statement sorts records in ascending order. If you want to sort records in descending order, you can use the DESC keyword. Original table (used in the example): Orders table: Company The order by statement is used to sort the result set.

Order by statement

The order by statement is used to sort the result set based on the specified column.

BY default, the order by statement sorts records in ascending ORDER.

If you want to sort records in descending order, you can use the DESC keyword.

Original table (used in the example ):

Orders table:

Company OrderNumber
IBM 3532
W3School 2356
Apple 4698
W3School 6953
Instance 1

Display company names in alphabetical order:

SELECT Company, OrderNumber FROM Orders ORDER BY Company
Result:
Company OrderNumber
Apple 4698
IBM 3532
W3School 6953
W3School 2356
Instance 2

Company is displayed in alphabetical order and OrderNumber is displayed in numerical order ):

SELECT Company, OrderNumber FROM Orders ORDER BY Company, OrderNumber

Result:

Company OrderNumber
Apple 4698
IBM 3532
W3School 2356
W3School 6953
Instance 3

Display company names in alphabetical order:

SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC
Result:
Company OrderNumber
W3School 6953
W3School 2356
IBM 3532
Apple 4698
Instance 4

Display company names in alphabetical order and sequence numbers:

SELECT Company, OrderNumber FROM Orders ORDER BY Company DESC, OrderNumber ASC
Result:
Company OrderNumber
W3School 2356
W3School 6953
IBM 3532
Apple 4698

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.