ColdFusion 4.0 Primer

5. Column Aliases
There may come a time when you wish to use aliases when referring to your columns. An alias is just a name you assign to a column to make it easier to refer to, it in no way changes your database, it only changes how the CF interpreter sees the column.

Figure 20. Aliases
<CFQUERY DATASOURCE = "Friends" name = "Query1">
Select DISTINCT FavMovie as Movie
From Friends
</CFQUERY>
.
.
.
<CFOUTPUT QUERY = "Query1">
#Movie#
</CFOUTPUT>

What the above would do is return a distinct list of your friends favorite movies. The only difference it has with a normal select statement is that within the page we can refer to the FavMovie column as Movie since we established the alias.

6. Aggregate Functions
Aggregate Functions are used to summarise the results from your queries. The most common use for this is to display the number of results returned from a search. To do this you must use the COUNT function.

Figure 21. Count Function
Select COUNT(*) as Friends
From Friends 

The above will return the number of friends you have. Notice the asterisk in the SQL, this is used because we want to simply count the total number of records. The asterisk can be replaced with a column name to just count the number of records in a particular column.

There are more aggregate functions of course, they are all used in the same way, and are listed below:

Count() - Counts the number of results.
Sum() - Calculates the total of values returned.
Avg() - Calculates the average of values returned.
Min() - Calculates the smallest value, earliest date, or first entry alphabetically.
Max() - Calculates the largest value, latest date, or last entry alphabetically.