Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The usage of Order By grammar in MySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report