Skip to main content
Known Participant
February 15, 2010
Answered

Query Of Queries : Error When Trying To Fake Left Outer Join

  • February 15, 2010
  • 1 reply
  • 4275 views

Hi there

I am trying to replicate a left outer join, combining two query of queries using a method I located here

However, I keep getting an error message..

Here is the code I am using....

    <cfquery dbtype="query" name="qry">
                SELECT *
                FROM returnQry, returnQry2
                WHERE returnQry.mediumImage = returnQry2.mediumImage
                ORDER BY returnQry.name   
            </cfquery>
                       
            <cfquery name="returnQry3" dbtype="#application.mx#">
                SELECT *
                FROM trackmeanings AS t
            </cfquery>      

           <cfquery dbtype="query" name="endQry">
                SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
                FROM qry, returnQry3
                WHERE qry.name = returnQry3.sNameTrack
                               
                UNION
               
                SELECT name,nameRcd,mediumImage, COUNT(sMessage) AS comments
                FROM qry, returnQry3
                WHERE #qry.name# NOT IN (#QuotedValueList(returnQry3.sNameTrack)#)
                GROUP BY name,nameRcd,mediumImage
            </cfquery>

When I try to use the query output in a page, i get the error message "Incorrect conditional expression,  Expected one of [like|null|between|in|comparison] condition"

Would anyone have any ideas?

Many thanks

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    The sql returned from the query is this

    SELECT name,nameRcd,mediumImage,COUNT(sMessage) AS comments

    FROM qry, returnQry3

    WHERE qry.name = returnQry3.sNameTrack

    GROUP BY name,nameRcd,mediumImage

    UNION

    SELECT name,nameRcd,mediumImage,COUNT(sMessage) AS comments

    FROM qry

    WHERE qry.name NOT IN (happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,Pigs,Hyph Mngo,Hyph Mngo,Hyph Mngo,Windowlicker,Windowlicker,Windowlicker,Rabbit In Your Headlights,You Do Something To Me,Everything You Do Is a Balloon,Vose In,Further,Lucy in the Sky With Diamonds,Magic America)

    GROUP BY name,nameRcd,mediumImage

    ORDER BY comments

    With the error

    Query Of Queries syntax error.
    Encountered "qry . name NOT IN ( happy cycling. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition.

    Many thanks


    The list items should be quoted.  Since you are using quotedvaluelist, it's odd that they are not.  Nonetheless, if you use cfqueryparam, list=yes, you should have better luck.  Among other things, it will protect you from apostrophe's in any of the names.

    1 reply

    Inspiring
    February 15, 2010

    The error is probably coming from the octothorps in the where clause of the lower half of your union query.  There is also a logic problem with that query.  The from clause of bottom part should only have one query, not two.

    namtaxAuthor
    Known Participant
    February 15, 2010

    Hi dan, thanks very much for your response, I have tried altering the union query but still getting errors, wondering how best to write the union query? many thanks

    Dan_BracukCorrect answer
    Inspiring
    February 15, 2010

    The sql returned from the query is this

    SELECT name,nameRcd,mediumImage,COUNT(sMessage) AS comments

    FROM qry, returnQry3

    WHERE qry.name = returnQry3.sNameTrack

    GROUP BY name,nameRcd,mediumImage

    UNION

    SELECT name,nameRcd,mediumImage,COUNT(sMessage) AS comments

    FROM qry

    WHERE qry.name NOT IN (happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,happy cycling,Pigs,Hyph Mngo,Hyph Mngo,Hyph Mngo,Windowlicker,Windowlicker,Windowlicker,Rabbit In Your Headlights,You Do Something To Me,Everything You Do Is a Balloon,Vose In,Further,Lucy in the Sky With Diamonds,Magic America)

    GROUP BY name,nameRcd,mediumImage

    ORDER BY comments

    With the error

    Query Of Queries syntax error.
    Encountered "qry . name NOT IN ( happy cycling. Incorrect conditional expression, Expected one of [like|null|between|in|comparison] condition.

    Many thanks


    The list items should be quoted.  Since you are using quotedvaluelist, it's odd that they are not.  Nonetheless, if you use cfqueryparam, list=yes, you should have better luck.  Among other things, it will protect you from apostrophe's in any of the names.