Home  >  Article  >  Database  >  How to set descending order in mysql query

How to set descending order in mysql query

WBOY
WBOYOriginal
2022-05-16 16:52:4018021browse

In mysql, you can use the desc keyword to display the query results in descending order. This keyword is the abbreviation of descend. It is often used in conjunction with the order by clause to make the query results in descending order. The syntax is "select field 1, field 2... from table name order by specified field desc".

How to set descending order in mysql query

The operating environment of this tutorial: windows10 system, mysql8.0.22 version, Dell G3 computer.

How to set descending order in mysql query

Use the desc keyword

What does desc mean?

desc is the abbreviation of [describe v. describe] and [descend v. drop].

desc and asc in mysql:

  • ##desc descending order(descend)

  • asc Ascend order (ascend)

1. Use desc to display the query results in descending order. It needs to be combined with the order by clause:

# Descending sql result statement format:

    select 字段1,字段2... from 表名 order by 指定字段 desc;

2. Use asc to display the query results in ascending order. It also needs to be combined with the order by clause:

# SQL result ascending statement format:

    select 字段1,字段2... from 表名 order by 指定字段 asc;

3. If you need two To display the fields in ascending and descending order, the following sql statement format is required:

    select 字段1,字段2... from 表名 order by 指定字段1 asc, 指定字段2 desc;

If there are any deficiencies in the content, please give me some advice...

Recommended learning:

mysql video tutorial

The above is the detailed content of How to set descending order in mysql query. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn