What do ASC and DESC do?
ASC and DESC are sort directions in SQL, used together with the ORDER BY operator.
ASC, ascending
Sorts from smaller to larger:
- numbers, from 1 to 1000,
- dates, from older to newer,
- text, alphabetically (A -> Z).
sql
SELECT name, salary
FROM employees
ORDER BY salary ASC;Returns employees starting with the lowest salary.
(ASC can be omitted, since it's the default value.)
DESC, descending
Sorts from larger to smaller:
- numbers, from 1000 to 1,
- dates, from newer to older,
- text, in reverse order (Z -> A).
sql
SELECT name, salary
FROM employees
ORDER BY salary DESC;Returns employees with the highest salary first.
Summary:
ASC-> from smaller to larger (ascending);DESC-> from larger to smaller (descending). Both set the sort direction afterORDER BY.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.