Did you find this useful?
Socialize it today.


SQL Order By Keyword

Friday, October 28, 2011

tags SQL

The ORDER BY keyword is used to sort the result-set by one or more specified fields (columns). The ORDER BY keyword sorts the records in ascending order by default. If you want to sort the records in a descending order, you can use the DESC keyword.


SQL ORDER BY Syntax

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s) ASC | DESC

ORDER BY Example

In this example, we will use the SELECT statement to build a result-set that includes all fields in the Customers table ordering the results by the LastName field.


SELECT *
FROM Customers
ORDER BY LastName

Same example but using the ORDER BY keyword to display the results in descending order.

SELECT *
FROM tbl_employees
ORDER BY employeeID

Results
employeeIDemployeeName
1000John Smith
1001Fred White
1002Jane Scott
1003Samuel Williams

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook