ORDER BY Clause

The ORDER BY clause is used to specify the order of the output data.

SELECT *
FROM [customer] ORDER BY [name]

Use the additional operators ASC and DESC to specify whether the results should be sorted in ascending or descending order. Without additional operators, the results are sorted in ascending order (ASC) by default.

SELECT *
FROM [customer]
ORDER BY [name] DESC

For the ORDER BY clause to also meet more complex demands, you can enter several element types for sorting.

SELECT [products].[name], [products].[priceperitem]
FROM [products]
WHERE [products].[priceperitem] <= 200
ORDER BY [products].[priceperitem] DESC, [products].[name]

Using the ORDER BY clause is only possible in the outermost query, not in subselects and not in partial queries linked by UNION or EXCEPT.