SQL Step-by-Step ORDER BY clause

Source: Internet
Author: User

ORDER BY clause

The syntax for the ORDER BY clause is:

SELECT Column1, SUM (Column2)

From "List-of-tables"

ORDER BY "Column-list" [ASC | DESC];

[] = optional

An order BY is an optional clause that allows you to display the results of a query according to the ascending or descending sequence of the columns that you specify to be ordered by. For example:

ASC = Ascending order– This is the default

DESC = descending order

Here's an example:

SELECT employee_id, Dept, name, age, salary

From Employee_info

WHERE dept = ' Sales '

Order by salary;

This SQL statement will list the dept equals ' Sales ' to select employee_id, dept, name, age, and salary from the Employee_info table, and list the results in ascending order according to their salary.

If you want to sort multiple columns, add commas between columns and columns, such as:

SELECT employee_id, Dept, name, age, salary

From Employee_info

WHERE dept = ' Sales '

Order by salary, age 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.