Lecture 9: ORDER BY sort query example of DQL data query statement

ORDER BY sort query example of DQL data query statement

1. Sorting query concept and syntax format

The so-called sorting query refers to sorting the results after the data results are queried. There are two sorting methods.

  • ASC: In ascending order of query results, it is also the default value.
  • DESC: In descending order of query results.

There are many application scenarios for sorting queries, such as various search indicators of e-commerce platforms, sorting by comprehensive indicators, sorting by price, sorting by sales, and so on.

The syntax of the sort query is: SELECT 字段列表 FROM 表名 ORDER BY 字段1 排序方式,字段2 排序方式2.

When using a sort query, you can apply different sorting rules to multiple fields at the same time, and the sorting will be sorted according to the order of the successive fields. For example, when two fields need to be sorted separately, only the leftmost field will be sorted, unless The second field will only be sorted if the first field value has the same result.

Guess you like

Origin blog.csdn.net/weixin_44953658/article/details/126554749