Select Rows in Descending Order in MySQL
Use the MySQL ORDER BY clause with the DESC keyword to return rows in descending order. Descending order means highest to lowest for numbers, latest to earliest for dates, and reverse collation order for text values.
In this MySQL Tutorial, we shall learn how to select rows of a table based on the descending order of values in a column.
MySQL ORDER BY DESC Syntax
To sort rows of a result set in descending order of values in a column, use the syntax of the following SQL Query.
SELECT * FROM table_name ORDER BY column_name DESC;
Replace table_name with the table to query and column_name with the column that determines the order. Unlike ASC, which is the default ordering direction, DESC must be written explicitly when descending order is required.
The ORDER BY clause is written after the FROM and optional WHERE clauses. When the query also uses LIMIT, place ORDER BY before LIMIT.
Sort the Students Table by Name in Descending Order
Consider the following students table.

Now we shall sort these rows in DESCENDING ORDER of name column.
Run the following query to sort the records in descending order.
SELECT * FROM students ORDER BY name DESC;

The query returns the same rows from the table, but arranges them by name in reverse order. The ORDER BY clause changes only the presentation of the result set; it does not rearrange or update rows stored in the table.
Select Specific Columns in Descending Order
You can select only the columns needed in the result while sorting by another column. The following query returns the student identifier and name, ordered by name from highest to lowest according to the column collation:
SELECT id, name
FROM students
ORDER BY name DESC;
The sorting column does not always need to be included in the selected column list. For example, this query displays names while ordering the rows by student identifier:
SELECT name
FROM students
ORDER BY id DESC;
Sort Numbers from Highest to Lowest with ORDER BY DESC
For a numeric column, descending order places the largest value first. The following query lists students from the highest age to the lowest age:
SELECT id, name, age
FROM students
ORDER BY age DESC;
Numeric data should normally be stored in a numeric data type such as INT or DECIMAL. Numbers stored in a character column are sorted as text, which can produce an order such as 9, 80, 7, and 10 rather than a true numeric descending order.
Sort Dates from Latest to Earliest in MySQL
Applying DESC to a DATE, DATETIME, or TIMESTAMP column places the most recent value first. For example:
SELECT id, name, admission_date
FROM students
ORDER BY admission_date DESC;
This pattern is commonly used to display recently added records, latest transactions, or newest events before older ones.
Sort by Multiple Columns in Descending Order
Specify multiple columns in the ORDER BY clause when the first sorting column may contain duplicate values. MySQL sorts by the first column and then uses each following column to resolve ties.
SELECT id, name, age
FROM students
ORDER BY age DESC, name DESC;
This query sorts students from the highest age to the lowest. Students with the same age are then sorted by name in descending order.
Each sorting column can have its own direction. The following query sorts ages in descending order but sorts names in ascending order when two students have the same age:
SELECT id, name, age
FROM students
ORDER BY age DESC, name ASC;
Resolve Equal Values with a Stable Secondary Sort
When several rows contain the same value in the sorting column, their relative order is not guaranteed unless another sorting expression is provided. Add a unique column such as the primary key to make the result predictable:
SELECT id, name, age
FROM students
ORDER BY age DESC, id DESC;
Rows with the same age are ordered by id, with the highest identifier first.
Return the Highest Values with DESC and LIMIT
Combine ORDER BY DESC with LIMIT when only the first rows from the descending result are needed. The following query returns the five oldest students:
SELECT id, name, age
FROM students
ORDER BY age DESC
LIMIT 5;
Without ORDER BY, a query using LIMIT 5 returns five matching rows but does not guarantee that they contain the five highest values.
Filter Rows Before Applying Descending Order
The WHERE clause filters rows before the remaining result is sorted. For example, the following query selects students aged 18 or above and then orders them from the highest age to the lowest:
SELECT id, name, age
FROM students
WHERE age >= 18
ORDER BY age DESC;
How MySQL Sorts Text and NULL Values with DESC
The order of text values depends on the column’s collation rather than only its character set. A collation defines comparison rules such as whether uppercase and lowercase letters or accented and unaccented characters are treated as equivalent.
In MySQL, NULL is treated as lower than non-NULL values for sorting. Therefore, NULL values normally appear after non-NULL values when a column is ordered with DESC.
To place NULL values first while keeping non-NULL ages in descending order, use an expression in the sorting clause:
SELECT id, name, age
FROM students
ORDER BY age IS NULL DESC, age DESC;
Sort by a Calculated Value or Column Alias
MySQL can sort a result by a calculated expression or by an alias defined in the SELECT list. The following query calculates a total score and places the highest total first:
SELECT name, mathematics + science AS total_score
FROM students
ORDER BY total_score DESC;
Using the alias in ORDER BY can make a query easier to read when the sorting expression is long.
Common MySQL ORDER BY DESC Mistakes
- Omitting DESC: MySQL uses ascending order by default, so
ORDER BY agedoes not return the highest age first. - Writing DESC before the column: Use
ORDER BY age DESC, notORDER BY DESC age. - Placing ORDER BY before WHERE: The correct order is
FROM,WHERE,ORDER BY, and thenLIMIT. - Expecting the table itself to be reordered:
ORDER BYaffects only the query result and does not modify stored rows. - Sorting numeric values stored as text: Character data follows text comparison rules rather than numeric magnitude.
- Ignoring duplicate sort values: Add a secondary column when rows with equal values must appear in a predictable order.
MySQL Descending Order FAQs
How do I select rows in descending order in MySQL?
Add ORDER BY column_name DESC to the query. For example, SELECT * FROM students ORDER BY name DESC; returns student rows ordered by name in descending order.
Is DESC the default sort direction in MySQL?
No. The default direction is ascending. You must include DESC explicitly to sort from highest to lowest, latest to earliest, or reverse alphabetical order.
How do I sort multiple columns in descending order?
Separate the columns with commas and specify a direction for each one, such as ORDER BY age DESC, name DESC. MySQL sorts by age first and then by name when ages are equal.
How do I get the highest value from a MySQL column?
Sort the column in descending order and limit the result to one row, such as SELECT * FROM students ORDER BY age DESC LIMIT 1;. Use a secondary sorting column when duplicate highest values require a predictable result.
Where do NULL values appear when using ORDER BY DESC?
In MySQL, NULL values normally appear after non-NULL values in descending order. An additional sorting expression can be used when NULL values should appear first.
Editorial QA Checklist for MySQL ORDER BY DESC
- Confirm that every descending example includes
DESCafter the relevant column or expression. - Verify that clause order follows
FROM, optionalWHERE,ORDER BY, and optionalLIMIT. - Check that numeric, text, and date examples describe the correct descending behavior for each data type.
- Confirm that multiple-column examples explain how later columns resolve equal values in earlier sort columns.
- Verify that the text-sorting explanation refers to collation and that the stated
NULLbehavior is specific to MySQL. - Confirm that the tutorial does not imply that
ORDER BYpermanently changes the physical order of table rows.
TutorialKart.com