<!--- 
 Filename: Distinct.cfm
 Created by: Nate Weiss (NMW)
 Purpose: Demonstrates use of SQL DISTINCT keyword
--->

<!--- Retrieve Expense Descriptions from Expense table; --->
<!--- This query may include any repeated descriptions --->
<cfquery name="getExp" datasource="#APPLICATION.DataSource#">
 SELECT Description
 FROM Expenses
 ORDER BY Description
</cfquery>

<!--- Retrieve Expense Descriptions from Expense table; --->
<!--- The DISTINCT means we won't get any repeated rows --->
<cfquery name="getUniqueExp" datasource="#APPLICATION.DataSource#">
 SELECT DISTINCT Description
 FROM Expenses
 ORDER BY Description
</cfquery>

<html>
<head><title>Film Expenses</title></head>
<body>
<h2>What Are We Spending Money On?</h2>

<table border="1">
  <tr valign="top">
    <!--- First, ordinary SELECT records --->
    <td>Ordinary SELECT statement:
    <ol>
    <cfoutput query="getExp">
    <li>#getExp.Description#</li>
    </cfoutput>
    </ol>
    </td>
    <!--- Now the SELECT DISTINCT records --->
    <td>SELECT DISTINCT statement:
    <ol>
    <cfoutput query="getUniqueExp">
    <li>#getUniqueExp.Description#</li>
    </cfoutput>
    </ol>
    </td>
  </tr>
</table>

</body>
</html>
