With a little side of applesauce...

Wednesday, September 8, 2010

Coldfusion Query of Queries - Get first and last row of resultset

Since Query of Queries does not have a LIMIT keyword, I found this work-around to be sufficient for grabbing the first and last rows of a resultset:
<cfquery dbtype="query" name="durationUserRecords">
SELECT * FROM getEventAttendance
WHERE email = <cfqueryparam value="#getEventAttendance.email#" cfsqltype="cf_sql_varchar" maxlength="50">
ORDER BY attendancetime ASC
</cfquery>
<cfset oldestTime = durationUserRecords [ "attendancetime" ][ 1 ]>
<cfset newestTime = durationUserRecords [ "attendancetime" ][ durationUserRecords.RecordCount ]>

2 comments:

Anonymous said...

will give you first record automatically

Shannon Eric Peevey said...

Yes, I added it as an example of how to reference a specific row.