Get the App
SLTechnology News&Howtos  ›  Database  › 

The usage of Order By grammar in MySQL

Shulou Source: shulou.com Published: 2022-05-31 18:00:30 09月19日 Update

This article introduces the knowledge of "the usage of Order By Grammar in MySQL". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

MySQL Order By keyword is used to classify the data in the record.

MySQL Order By Keyword classifies according to keywords

ORDER BY keyword is used to classify the data in the record.

MySQL Order By syntax

SELECT column_name (s)

FROM table_name

ORDER BY column_name

Note: SQL statements are case-insensitive (it is not case-sensitive), that is, "ORDER BY" and "order by" are the same.

MySQL Order By case

The following example: select all records from the "Person" table and classify the "Age" column:

The above code will output the following result:

Glenn Quagmire 33

Peter Griffin 35

Sort according to ascending or descending order

If you use the "ORDER BY" keyword, all records will be sorted in the default ascending order (that is, from 1 to 9, from a to z)

Use the "DESC" keyword to make all the data in descending order (that is, from 9 to 1, from z to a):

SELECT column_name (s)

FROM table_name

ORDER BY column_name DESC

MySQL Order By classifies according to two columns

In many cases, we need to classify data according to two columns (or more columns) at the same time. When you specify more than one column, refer to the second column only if the values of the first column are exactly the same:

SELECT column_name (s)

FROM table_name

ORDER BY column_name1, column_name2

This is the end of the introduction to the usage of Order By Grammar in MySQL. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Tags: Classification data grammar key keywords content more faceted ascending order size letters cases knowledge statements output practical identical learned next code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Shulou Tech Info Docker MySQL