Encountered "(. Incorrect Select Statement, Expecting a 'FROM', But Encountered '(' Instead, A Select Statement Should Have a 'FROM' Construct.

Posted June 30, 2006 at 12:08 PM by Ben Nadel

Tags: ColdFusion, SQL

I was testing some ColdFusion Query of Queries functionality when I got this error:

Query Of Queries syntax error.
Encountered "(. Incorrect Select Statement, Expecting a 'FROM', But Encountered '(' Instead, A Select Statement Should Have a 'FROM' Construct.

I know what was causing the error because I was testing to see if something worked, but it's not the most obvious error. I guess it's a syntax error (from a technical standpoint), but in my case, where I was testing to see if ISNULL() worked, I'm really using a function that is not available.

That being said, if you get the error above, it means you are using something in the SELECT statement that is not allowed. If you are coming over from SQL, make sure you are not trying to use any SQL functions that are not available in the ColdFusion Query of Queries. As a foot note, here are some common SQL functions that I use that are not available in the ColdFusion Query of Queries:

ISNULL()
LEN()
DATEADD()



Reader Comments

Mar 31, 2007 at 11:25 PM // reply »
24 Comments

Hrm...

In my case, I have an XML file which I'm converting into a query object. The resulting query has a column named date. I can select * just fine, but when I specify the date column it blows up. Leave that column out and it works just fine. I've tried bracketing the column name, quoting it bracketing AND quoting to no avail.

Anyone have any ideas?


Mar 31, 2007 at 11:43 PM // reply »
24 Comments

Okay...

In this case, the solution was ot both bracket AND alias the questionable column. So this works:

SELECT [date] AS thedate
FROM QofQ


Apr 1, 2007 at 9:37 AM // reply »
11,246 Comments

Exactly... in fact, the same thing would apply to a regular non-query-of-queries SQL statement.


Oct 3, 2007 at 10:53 AM // reply »
4 Comments

I've run into this error as well using the COUNT function. It only works when i have just the function in the SELECT list and use no alias which is worthless for my purposes.


Mar 22, 2010 at 7:21 AM // reply »
6 Comments

I got this exception now.
In case you're using var-es local struct, CF gives you couple of "new" exceptions:

Encountered "local.

and

Encountered "id. Incorrect Select List, Incorrect select column

This is the way out:

<cfset var local = structNew() >
<cfset local.query = something... >
<cfquery name="local.queryOfQueries" dbtype="query" >
SELECT [id],
[columnId]
FROM [local].query
WHERE [columnId] IN ( ...cfqueryparam list output...)
ORDER BY [id] ASC
</cfquery>

Those who work with MS SQL Server should recognize this syntax.


Mar 22, 2010 at 6:40 PM // reply »
11,246 Comments

@Zarko,

Yeah, the [local] notation still trips me up from time to time.


May 4, 2010 at 3:25 PM // reply »
5 Comments

Ben,

You consistently give excellent explanations to most of the problems I have. Thank you for your service to the CF community!


May 4, 2010 at 3:30 PM // reply »
11,246 Comments

@Kate,

Thanks Kate! Hey, you going to CFUnited this year?


May 4, 2010 at 3:32 PM // reply »
5 Comments

Wouldn't miss it. See you there!


May 4, 2010 at 3:42 PM // reply »
11,246 Comments

Woohooo!


May 24, 2012 at 11:25 AM // reply »
12 Comments

I'm sure this is already a known fact but figured I'd mention it anyways just in case some unsuspecting soul tries it:

What works in QoQ:

select myQuery1.name, myQuery2.city
from myQuery1, myQuery2
where myQuery1.id = myQuery2.id

What won't work:

select qry1.name, qry2.city
from myQuery qry1, myQuery qry2
where qry1.id = qry2.id

Aliasing won't work, or I'm doing something wrong.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 24, 2013 at 5:39 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Adam Oops! My mistake! I hadn't gotten that far in my testing - I'm still baby stepping my way through the process. ... read »
May 24, 2013 at 5:13 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
Hi Jason, Thanks for checking up on that, but I still stand firm on my position. :) There are actually two listLast()'s in use, and you're right that the one using a space as a delimiter is fine. ... read »
May 24, 2013 at 4:45 PM
Ask Ben: Manually Enforcing Basic HTTP Authorization In ColdFusion
@Ben I have been lurking your site for quite some time, and haven't stepped up to comment until today. Thanks for all the great info - keep it up! @Adam I believe you are mistaken... as the commen ... read »
May 24, 2013 at 11:21 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@WebManWalking, Ha ha, let's us never speak of justifying "##" notation again :P ... read »
May 24, 2013 at 11:18 AM
Strange Interaction Between DeserializeJson(), ArrayContains(), And Database Values In ColdFusion
@Ben, Ah, so it was indeed how I vaguely remembered it to be: A direct assignment value = users.id[ i ] causes value to retain the sticky datatype of the query column. Although unnecessary in ... read »
May 24, 2013 at 9:11 AM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Brandon, Hi, No, I haven't been able to do that. I have just kept it as it is. ... read »
May 23, 2013 at 9:52 PM
Preventing Links In Standalone iPhone Applications From Opening In Mobile Safari
@Muhmmadibn Did you figure out a solution to launching PDFs? I am running into the same issues myself. There is no way to close the PDF or go back once you launch it. Thanks in advance! ... read »
May 23, 2013 at 6:06 PM
The Girl Who Broke My Heart, And Made Me A Better Person
Good day,ladies and gentle men, my name is Dr AMADI the great spell caster in Africa, i have help so many people for different kind of problems,who say there is no solution to problems on earth, that ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools