MSDN Documentation

ORDER BY Clause

The ORDER BY clause sorts the result set of a SELECT statement according to one or more columns or expressions.

Syntax

SELECT column_list
FROM table_name
[WHERE condition]
[ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...];

Key Points

Examples

-- Sort employees by last name ascending
SELECT FirstName, LastName, HireDate
FROM Employees
ORDER BY LastName;

-- Sort products by price descending, then name ascending
SELECT ProductName, Price
FROM Products
ORDER BY Price DESC, ProductName ASC;

Interactive Demo

Try sorting the sample data below:

ID Name Salary Hire Date
3Alice Johnson720002019-04-12
1Bob Smith850002017-08-03
5Carol Lee660002020-01-15
2David Kim920002015-06-21
4Evelyn Chen780002018-11-30