Posted in ColdFusion | Posted on 07-02-2009 | 3,906 views
A user reported this to me earlier in the week. I was sure he was wrong until I confirmed it myself. Imagine you have 2 queries you want to join using a query of query. Here is a quick sample.
2select id, title,posted
3from tblblogentries
4order by posted desc
5</cfquery>
6<cfquery name="q2" datasource="blogdev" maxrows="5">
7select id, title,posted
8from tblblogentries
9order by posted asc
10</cfquery>
Admittedly, this is kind of a dumb example, but I wanted to keep it simple. q is a query sorted by posted, descending, and q2 is the reverse of that. To join with query of queries, you must use a where clause, you can't use join. Here is the QofQ I used:
2select q.posted, q.id, q.title, q2.id as qid
3from q,q2
4where q.id = q2.id
5order by q.id asc
6</cfquery>
Note that I gave the new query the name z. Everything should be kosher, right? Well watch what happens when I dump q before and after the query of query.
What the heck, right? The error goes away if you make a duplicate of q and use that in the query of query.


I am trying to use string functions in QofQ like LEFT(string, count), or RIGHT(string, count) and I have:
" Query Of Queries syntax error.
Encountered "Left. Incorrect Select List, Incorrect select column".
For first query I am using a :
<cfdirectory directory="#application.installPath##application.PDFfilesDir#" name="memberList" action="LIST" sort = "directory ASC">
Then,
<cfquery dbtype="query" name="reportsQuery">
SELECT distinct Name, Left(Name, 12) AS PDF
FROM memberList
</cfquery>
I need to show only first 12 charachters in the <cfselect>
[Add Comment] [Subscribe to Comments]