How To Use SQL Order By Descending With Several Example?
Summary: In this article, you will learn how to use SQL ORDER BY Descending and how its work with Order By Clause of The SQL Statement With Example to sort the result and set a query by one or more columns.
SQL Order By Descending Keyword
The SQL Server ORDER BY clause can be used to sort the data without specifying the ASC or DESC value. When this attribute is omitted from the ORDER BY SQL clause, the sort order is defaulted to ascending order or ASC. but when you want to sort records to descending order then you need to use DESC.
Syntax:
The SQL ORDER BY Descending syntax given as below:
FROM tables
[WHERE conditions] ORDER BY expression DESC;
Here,
- expressions:– expressions defined here the column(s) you want to retrieve. If you want to retrieve all the columns just generally use * in the place of expressions.
- tables:– one or over one table from wherever you wish to retrieve data.
- WHERE conditions:– It is optional. Basically, it is used to mention some conditions while selecting data. just in case you’re not using the WHERE clause, all the rows available will be selected.
- ORDER BY:– This keyword is used to sort the result set. If you wish to kind on over one column, you need to provide them in a comma-separated.
- DESC:– When using the DESC keyword, then it sorts the result set in descending order. this is often the default behavior if no modifier is mentioned.
Note: The SQL Server (Transact-SQL) ORDER BY keyword is used to sort the records in your result set. The SQL ORDER BY clause can only be used in SELECT statements.
If within the SQL statements ASC (ascending order) or DESC (descending order) modifier isn’t provided within the ORDER BY SQL keyword, then the results are going to be sorted by expression in ASC or ascending order. this suggests that it’s equivalent to ORDER BY expression ASC.
Demo Database Table
Let’s Consider an Students table with the following data.
StudentsID | Name | Age | course | Fees |
---|---|---|---|---|
1 | Alfreds Futterkiste | 18 | 12th | 5200 |
2 | Blauer See Delikatessen | 21 | B.Tech | 34000 |
3 | Ana Trujillo | 26 | MBA | 23000 |
4 | Hanna Moos | 24 | BA | 12000 |
5 | Victoria Ashworth | 28 | Data Science | 41000 |
6 | Elizabeth Lincoln | 27 | B.Tech | 34000 |
7 | Martín Sommer | 26 | LLB | 23000 |
8 | Elizabeth Brown | 22 | B.Com | 21000 |
9 | Pedro Afonso | 24 | MBA | 25000 |
10 | Yang Wang | 26 | Data Science | 45000 |
11 | Francisco Chang | 28 | LLB | 25000 |
12 | Janine Labrune | 30 | CA | 22000 |
13 | Sven Ottlieb | 27 | B.Com | 21000 |
14 | Roland Mendel | 26 | CA | 23000 |
15 | Lino Rodriguez | 25 | B.Tech | 32000 |
Example:-1
The given below SQL statement sorts the result in Decending order by “NAME”.
1 2 |
SELECT * FROM Students ORDER BY NAME DESC; |
Example:-2
The given below SQL statement sorts the result in Desending order by “course”.
1 2 |
SELECT * FROM Students ORDER BY course DESC; |

Example:-3
In this SQL statement, When we sort the result set in descending order, then we need to use the DESC attribute in your ORDER BY Keyword.
1 2 3 4 |
SELECT Name, course, Fees FROM Students WHERE Name = 'Hanna Moos' ORDER BY Name DESC; |
OUTPUT: This SQL Server ORDER BY Descending example would return all records sorted by the Name field in descending order.