> Hello everyone. I am running into a problem with my cfquery tag and I
> was wondering if anyone out there could give me a hand with this.
> Basically I am querying a database that has a series of records. But
> when I output the information from the database I only want to select
> the newest record that was entered. I have a field in the database that
> keeps track of the time and date of the information entered.
>
> Here is the query statement that I am using. I am able to sort the
> content depending on the date but it still spits out all of the records
> instead of just the "newest" one.
>
> <cfquery name="OutputUnitContent" datasource="camp" dbtype="ODBC">
> Select *
> from UnitPages
> where ArticleUnit = '#form.units#'
> order by ArticleDate DESC
> </cfquery>
>
> If anyone has an idea how to do this I would really appreciate your
> help.
OK, firstly, if you only want to use the first record then don't let CF do
it - if you have millions of records, SQL will have to hand them to CF
before it can do it
Try;
<cfquery name="OutputUnitContent" datasource="camp" dbtype="ODBC">
Select top 1 *
from UnitPages
where ArticleUnit = '#form.units#'
order by ArticleDate DESC
</cfquery>
This will literally return the top row, and nothing else
Philip Arnold
Director
Certified ColdFusion Developer
ASP Multimedia Limited
T: +44 (0)20 8680 1133
"Websites for the real world"
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
**********************************************************************
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists