How do I re-sort a query?
If you have a database query that is not sorted, or is sorted by the wrong column, you may have a need to re-sort the query by a new column. ColdFusion's query of query functionality makes this simple. The following code sample shows an example:
<cfquery name="original" datasource="foo"> select name, age, rank from people order by age asc </cfquery> <!--- Resort by name ---> <cfquery name="newQuery" dbtype="query"> select name, age, rank from original order by name asc </cfquery>
When using query of queries, notice that we do not provide a datasource, but rather we tell ColdFusion that the dbtype is query. Also note how the from portion of the sql refers to the variable (original) that has the original query.
This question was written by Raymond Camden
It was last updated on March 23, 2006.