Changes

Sorting Data Retrieved from a MySQL Database

11 bytes removed, 20:03, 11 October 2007
Sorting data retrieved using SELECT
Now that we have looked at the basics of [[Retrieving Data From a MySQL Database|retrieving data from a MySQL database]] and before we look and [[filtering retrieved data]] we need to look at how to sort the output from a database retrieval.
== Sorting SELECTed data retrieved using SELECT ==
In the previous chapter we look at the SQL SELECT statement and how it is used to retrieve data from a database. Typically, a SELECT statement will extract the data from a table in the order in which it was added. Thius, however, can change if the database table has been subjected to updates and deletions. Quite simply, there is no way to predict the exact order in which data will be retrieved. For this reason SQL provides the ''ORDER BY'' keywords which enable us to sort the data as it is retrieved by the SELECT statement.
</pre>
It is not necessary to sort on the selected column when retrieving data. it It is perfect perfectly valid to sort on any column in a table , regardless of whether it is one of the columns referenced in a SELECT statement.
== Sorting on Multiple Columns ==