Loading Data Driven Insights
Preparing your learning content.
Preparing your learning content.
A beginner-friendly guide to the SQL ORDER BY clause, with SQL Server-friendly examples for sorting query results in ascending and descending order.
On this page
Jump to a lesson section
The ORDER BY clause is used to sort query results.
You can sort data by names, salary, dates, numbers, and grouped results.
ORDER BY is usually written at the end of the query.
SELECT
column_name
FROM table_name
ORDER BY column_name;
SELECT
employee_name,
department,
salary
FROM Employees
ORDER BY salary;
We will sort this Employees table using ORDER BY.
Use ASC to sort values in ascending order. For numbers, this means low to high.
SELECT
employee_name,
department,
salary
FROM Employees
ORDER BY salary ASC;
Use DESC to sort values in descending order. For numbers, this means high to low.
SELECT
employee_name,
department,
salary
FROM Employees
ORDER BY salary DESC;
ORDER BY sorts the final result.ASC for low to high.DESC for high to low.Use ASC for ascending order and DESC for descending order.
SQL Roadmap Progress
Topic 21 of 111
19% complete
Next in SQL Roadmap
Continue with the next SQL topic in the recommended roadmap order.
Continue learning →