SQL explained: What is SQL | Select Statement | Select Where | Insert | Update/Edit | Delete | Order By | Select Between
The ORDER BY clause allows you to sort the retrieved records.
Syntax: SELECT * FROM TableName ORDER BY FieldName ASC/DESC
The ASC keyword selects the results in ascending order. Ascending order is the default and the ASC keyword can be left out. The DESC keyword returns the results in descending order.
If we wanted to select all the records in our database table below in Diagram1 and sort them in alphabetical order based on the FirstName field we could use the SQL statement below.
SELECT * FROM Members_tbl ORDER BY FirstName
| Diagram 1 |
![]() |
The first record retrieved would be the row with Dave Jones would lives
in 32 Donki Park in Belfast as Dave comes alphabetically before Henry
and Michael.
To return the rows in reverse alphabetical order based on the FirstName
field we could use the SQL statement below.
SELECT * FROM Members_tbl ORDER BY FirstName DESC
Get the best asp web hosting provider now and save 30%
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.