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.
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.
Learning SQL in order?
Use the roadmap to follow each SQL topic step by step, from relational database basics to advanced query techniques.
Back to SQL RoadmapRelated lessons
ALTER TABLE
A beginner-friendly guide to ALTER TABLE in SQL, including how to add, change, and remove columns from an existing table.
CREATE TABLE
A beginner-friendly guide to the SQL CREATE TABLE statement, including table planning, column names, data types, and a SQL Server-friendly example.
DELETE
A beginner-friendly guide to the SQL DELETE statement, with SQL Server-friendly examples for removing rows from a table safely.