Sort

Functionality:

Can specify sorting field and sorting direction to display query result in the desired order.

Syntax:

SELECT select_list

FROM  T

WHERE search_condition

ORDER BY order_expression[ ASC | DESC ], ......

Parameter:

order_expression

Sorting field or sorting expression

ASC

Ascending order

DESC

Descending order

Example:

 

SELECT OrderID,CustomerID,EmployeeID,ReceiveDate,ShipDate,Amount

FROM Orders  ORDER BY Amount  DESC

Sort by Amount in descending order

SELECT OrderID,CustomerID,EmployeeID,ReceiveDate,ShipDate,Amount

FROM Orders  ORDER BY EmployeeID

Sort by EmployeeID in ascending order; ascending order is default when no sorting direction is specified

SELECT EmpID,Name,Title,age(BirthDate) Age,HireDate,Boss,HomeCity

FROM Employee  ORDER BY Age DESC,HireDate ASC

Sort by age in descending order and then by hire date in ascending order