Ordering the recordset returned from your Access database is very easy - simply specify the columns you wish to order using an ORDER BY clause. When using the ORDER BY clause, ordering will happen by default in Ascending order (lowest to highest value). To order from highest to lowest value all you do is simply add the DESC keyword.
Some examples of ordering using the ORDER BY clause can be seen below.
Below is a table called 'Members_tbl' with 3 rows of data.
| Diagram 1 |
![]() |
SELECT * FROM Members_tbl ORDER BY ID
The above SQL statement will return all the data in Ascending Order based
on the ID column. The row with the ID of 1 and with Michael Wall in it
will be the first returned.
If it was:
SELECT * FROM Members_tbl ORDER BY ID DESC
Then the row with Henry Cole would be the first, simple!
Ordering by Date/Time fields
| Diagram 2 |
![]() |
You will notice that from the table above (Diagram 2), all the members have joined on the same day, the only difference is the time that they have joined.
If we were to do a SELECT * FROM Members_tbl ORDER By DateJoined this would return all the data in Ascending order based on the DateJoined field. (Remember ASC ascending is the default). In this scenario 'Michael Wall' would be the first returned as he has joined just 1 minute and 2 seconds before 'Fred Humphries'.
If we were to do a SELECT * FROM Members_tbl ORDER By DateJoined DESC then this would return 'David Goose' first.
Below is sample code using the table structure in Diagram 2;
| Previous: INSERT Form Content to Database (Part 2) |
Next: Return Top 10 Records |
Plug and play ASP membership script that integrates with PayPal to let you charge recurring membership fees.
Get your best asp web hosting provider now and save 25%