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

How to use order by sorting to retrieve data in Mysql

2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about how to use order by sorting to retrieve data in Mysql. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

In myslq data, the retrieved data is often displayed in the order in which the underlying data is added to the table, but there may be update and delete operations, which will affect the sort order, and all the data queried from the data without specifying the sort order is meaningless. Here you need to use the Oderby clause to sort the data.

Mysql | orderby sort and retrieve data (ASC,DESC)

EG:

SELECT*FROMproductsORDERBYproducts.prod_priceDESC,products.prod_nameASC

Explanation:

DESC: stands for descending order.

ASC: stands for ascending order. (do not write the default value)

The query results are sorted in descending order according to products.prod_price, and then the records with the same products.prod_price are sorted according to the descending order of products.prod_name. If there are more sort fields separated by commas.

Note:

When sorting textual text, whether the sort is sorted according to case, such as whether an is before B or after Z, depends on the setting of the database, it is impossible to sort statements.

ORDERBYDESC instance

SQLORDERBY keyword

The ORDERBY keyword is used to sort the result set by one or more columns.

The ORDERBY keyword sorts records in ascending order by default. If you need to sort the records in descending order, you can use the DESC keyword.

SQLORDERBY syntax

SELECTcolumn_name,column_name

FROMtable_name

ORDERBYcolumn_name,column_nameASC | DESC

Demo database

In this tutorial, we will use the RUNOOB sample database.

The following SQL statement selects all sites from the "Websites" table and sorts them in descending order by the "alexa" column:

Case study

SELECT*FROMWebsites

ORDERBYalexaDESC

Thank you for reading! This is the end of this article on "how to use order by sorting to retrieve data in Mysql". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

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

Development

Wechat

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

12
Report