Can I get a query row by index in ColdFusion?

Brian Bolton picture Brian Bolton · Jul 31, 2009 · Viewed 59.1k times · Source

I want to get a specific row in a ColdFusion Query object without looping over it.

I'd like to do something like this:

<cfquery name="QueryName" datasource="ds">
SELECT *
FROM    tablename
</cfquery>

<cfset x = QueryName[5]>

But it's giving me an error saying that the query isn't indexable by "5". I know for a fact that there are more than 5 records in this query.

Answer

Patrick McElhaney picture Patrick McElhaney · Jul 31, 2009

You can't get a row in CF <= 10. You have to get a specific column.

<cfset x = QueryName.columnName[5]>

It's been 8 years since I posted this answer, however. Apparently CF11 finally implemented that feature. See FrankieZ's answer.