Querying a query using the CFQUERY tag in ColdFusion

Readability

Querying a query using the CFQUERY tag in ColdFusion

The fol­low­ing exam­ple shows how you can query an exist­ing query object by set­ting the dbtype attribute to “query” on a <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
    ORDER BY a.PRICE DESC





SELECT * FROM getArt WHERE ISSOLD = 1 ORDER BY PRICE DESC

And the out­put of the <CFDUMP> tag is as fol­lows:
Query of Query (QoQ) on a CFQUERY tag

The following example shows how you can query an existing query object by setting the dbtype attribute to “query” on a <CFQUERY> tag in ColdFusion.

<cfquery name="getArt" datasource="cfartgallery">
    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
    ORDER BY a.PRICE DESC
</cfquery>
 
<cfdump var="#getArt#" label="getArt query" top="5" />
 
<hr />
 
<cfquery name="getSoldArt" dbtype="query">
    SELECT *
    FROM getArt
    WHERE ISSOLD = 1
    ORDER BY PRICE DESC
</cfquery>
 
<cfdump var="#getSoldArt#" label="getSoldArt query" top="5" />

And the output of the <CFDUMP> tag is as follows:
Query of Query (QoQ) on a CFQUERY tag

Leave a Reply

Your email address will not be published.