Using Query Results in Queries
35
You can also do the following tasks:
•
Use the results of one or two queries in your SQL statement.
•
Generate computed columns.
Performing a query on a query
To generate a query using an existing query:
•
Specify the
cfquery tag’s
dbtype
attribute as "
query".
•
Do not specify a
datasource
attribute.
•
Specify the names of one or more existing queries as the table names in a SQL
SELECT statement.
•
If the database content does not change rapidly, it is a good idea to use the
cachedwithin
attribute to cache the query results of between page requests. This
way, ColdFusion accesses the database on the first page request, and does not
query the database again until the specified time expires. Note that you must use
the
CreateTimeSpan
function to specify the
cachedwithin
attribute value.
Note
You cannot add a literal value as a column to the SELECT list in a query of queries.
Your query generates a new query results set, identified by the value of the
name
attribute. The following example illustrates the use of a master query and a single
detail query that extracts information from the master. A more extended example
would use multiple detail queries to get different information from the same master
query.
Boolean predicates:
LIKE
NOT LIKE
IN
NOT IN
BETWEEN
NOT BETWEEN
AND
OR
Aggregate functions:
Count([DISTINCT][*] expr)
Sum([DISTINCT] expr)
Avg([DISTINCT] expr)
Max(expr)
Min(expr)
You cannot nest aggregate
functions.
Comparison operators:
<=
>=
=
<
>
<>
Summary of Contents for COLDFUSION 5-DEVELOPING
Page 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Page 58: ...38 Chapter 3 Querying a Database ...
Page 134: ...114 Chapter 7 Updating Your Database ...
Page 210: ...190 Chapter 10 Reusing Code ...
Page 232: ...212 Chapter 11 Preventing and Handling Errors ...
Page 238: ...218 Chapter 12 Using the Application Framework ...
Page 262: ...242 Chapter 12 Using the Application Framework ...
Page 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Page 320: ...300 Chapter 15 Indexing and Searching Data ...
Page 336: ...316 Chapter 16 Sending and Receiving E mail ...
Page 374: ...354 Chapter 18 Interacting with Remote Servers ...