The following examples demonstrate ordering of a result set.
Ordering by the numerical ProductID column. The default is ascending order.
USE AdventureWorks
GO
SELECT ProductID, Name FROM Production.Product
WHERE Name LIKE 'Lock Washer%'
ORDER BY ProductID ;
Ordering by the numerical ProductID column in descending order.
SELECT ProductID, Name FROM Production.Product
WHERE Name LIKE 'Lock Washer%'
ORDER BY ProductID DESC;
Ordering by the Name column. Note that the characters are sorted alphabetically, not numerically. That is, 10 sorts before 2.
SELECT ProductID, Name FROM Production.Product
WHERE Name LIKE 'Lock Washer%'
ORDER BY Name ASC ;
Ordering by two columns. This query first sorts in ascending order by the FirstName column, then sorts in descending order by the LastName column.
SELECT LastName, FirstName FROM Person.Contact
WHERE LastName LIKE 'R%'
ORDER BY FirstName ASC, LastName DESC ;