SQL Keywords

SQL DESC

What does SQL DESC do?

DESC sets descending sort order for a column or expression in an ORDER BY clause.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL DESC: PostgreSQL, MySQL, SQL Server, Oracle, SQLite, Snowflake, BigQuery, Redshift

SQL DESC Full Explanation

DESC is the companion to ASC in the ORDER BY clause. When applied to a column, expression, or ordinal position in ORDER BY, it instructs the database engine to return rows with the highest values first. If multiple columns are listed, each DESC or ASC modifier affects only the column that precedes it. When no modifier is supplied, most dialects default to ASC (ascending). DESC applies after the result set is filtered (WHERE), grouped (GROUP BY), and projected (SELECT) but before pagination (LIMIT, OFFSET, FETCH FIRST) is evaluated. Handling of NULL values differs by dialect: PostgreSQL and Oracle allow explicit NULLS FIRST or NULLS LAST, while MySQL orders NULLs first in DESC by default. DESC is a keyword, not a standalone statement, and should not be confused with DESCRIBE, the MySQL shorth​and for SHOW COLUMNS.

SQL DESC Syntax

SELECT column_list
FROM table_name
ORDER BY column_name DESC;

SQL DESC Parameters

Example Queries Using SQL DESC

-- Get the 10 most expensive products
SELECT product_id, name, price
FROM products
ORDER BY price DESC
LIMIT 10;

-- Sort invoices by date descending, then by amount ascending
SELECT invoice_id, invoice_date, total
FROM invoices
ORDER BY invoice_date DESC, total ASC;

Expected Output Using SQL DESC

  • Rows are returned with the highest price or most recent date first
  • All other query clauses behave normally

Use Cases with SQL DESC

  • Fetching top-N rows such as highest salaries or latest timestamps
  • Reversing chronological order to create timelines
  • Supporting pagination where the first page should show newest items
  • Building reports that require max-to-min ordering

Common Mistakes with SQL DESC

  • Using DESC outside ORDER BY
  • Assuming DESC applies to all listed columns when only one is specified
  • Forgetting NULL handling differences across dialects
  • Confusing DESC with DESCRIBE

Related Topics

ORDER BY, ASC, NULLS FIRST, NULLS LAST, LIMIT, FETCH FIRST

First Introduced In

SQL-92

Frequently Asked Questions

What does DESC mean in ORDER BY?

DESC means descending. The database returns the highest values first for the specified column or expression.

Does DESC change grouping or filtering?

No. DESC only affects the final ordering of rows. WHERE, GROUP BY, and HAVING are processed first.

Can I mix DESC and ASC in the same ORDER BY?

Yes. Add DESC or ASC after each column as needed. Each modifier affects only the column directly before it.

How do I force NULLs to the end while using DESC?

In PostgreSQL or Oracle append NULLS LAST. In SQL Server use ORDER BY CASE WHEN col IS NULL THEN 1 ELSE 0 END, col DESC. MySQL does this automatically.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!