Specifying a maximum number of results from a query using the CFQUERY tag in ColdFusion

Readability

Specifying a maximum number of results from a query using the CFQUERY tag in ColdFusion

In a pre­vi­ous exam­ple, “Query­ing a data­base in Cold­Fu­sion using the CFQUERY tag”, we saw how you could query a data­base in Cold­Fu­sion 9 using the <CFQUERY> tag.

The fol­low­ing exam­ple shows how you can restrict the num­ber of results from a data­base query by set­ting the maxRows attribute on the <CFQUERY> tag in ColdFusion.


    SELECT a.ARTID, a.ARTNAME, a.DESCRIPTION, a.ISSOLD, a.LARGEIMAGE, m.MEDIATYPE, a.PRICE
    FROM ART a, MEDIA m
    WHERE a.MEDIAID = m.MEDIAID
        AND a.ISSOLD = 0
    ORDER BY a.PRICE DESC



And the out­put of the <CFDUMP> tag is as fol­lows:
Setting the maxRows attribute on the CFQUERY tag

In a previous example, “Querying a database in ColdFusion using the CFQUERY tag”, we saw how you could query a database in ColdFusion 9 using the <CFQUERY> tag.

The following example shows how you can restrict the number of results from a database query by setting the maxRows attribute on the <CFQUERY> tag in ColdFusion.

<cfquery name="getArt" datasource="cfartgallery" maxRows="5">
    SELECT a.ARTID, a.ARTNAME, a.DESCRIPTION, a.ISSOLD, a.LARGEIMAGE, m.MEDIATYPE, a.PRICE
    FROM ART a, MEDIA m
    WHERE a.MEDIAID = m.MEDIAID
        AND a.ISSOLD = 0
    ORDER BY a.PRICE DESC
</cfquery>
 
<cfdump var="#getArt#" />

And the output of the <CFDUMP> tag is as follows:
Setting the maxRows attribute on the CFQUERY tag

Leave a Reply

Your email address will not be published.