Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Order By Desc in SQL

Order By Desc in SQL

ORDER BY DESC in SQL

The ORDER BY DESC clause sorts the result set of a query in descending order — from the largest to smallest values.


? Syntax:

SELECT column1, column2, ...FROM table_nameORDER BY column_name DESC;
  • DESC means descending order.

  • For numbers, it sorts from highest to lowest.

  • For text, it sorts from Z to A.

  • For dates, it sorts from newest to oldest.


? Example:

Get all employees ordered by salary from highest to lowest:

SELECT employee_name, salaryFROM employeesORDER BY salary DESC;

Multiple columns example:

Order by department ascending and within department, order employees by salary descending:

SELECT employee_name, department_id, salaryFROM employeesORDER BY department_id ASC, salary DESC;

Notes:

  • If DESC is omitted, the default order is ASC (ascending).

  • Can be combined with other clauses like WHERE, GROUP BY, etc.

  • Useful for getting top values, e.g., highest salaries, latest dates.


Want me to show how to get the top N rows after sorting with ORDER BY DESC?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql