2

I want to use a query of queries as a subquery but i get a syntax error: Encountered "(. Here is my query (qHistoryData is my query object):

<cfquery dbtype="query">
    SELECT *
    FROM (
        SELECT 
            t2.*,
            ROW_NUMBER() OVER(
                PARTITION BY collectid
                ORDER BY update_on DESC
            ) AS seqnum
        FROM qHistoryData t2
    ) t
    WHERE t.seqnum = 1;
</cfquery>
11
  • 2
    Is this a simplified version of your real query? This looks perfectly valid to me. Commented Oct 28, 2019 at 14:26
  • 2
    @VBokšić I use Oracle and my error is: Query of Queries syntax error. Encountered "(. I do not get anything more as an error. Commented Oct 28, 2019 at 14:31
  • 1
    Well as @Andrew said it looks ok. Here is the demo : dbfiddle.uk/… Commented Oct 28, 2019 at 14:37
  • 6
    ROW_NUMBER() and OVER() are not supported by queries of queries. Commented Oct 28, 2019 at 14:50
  • 4
    As others have already mentioned, ColdFusion query of queries is limited in it's SQL abilities. It is not a full blown implementation. Here is a link that describes the syntax and it's limitations Commented Oct 28, 2019 at 15:03

1 Answer 1

4

A Query of Queries is implemented entirely at the ColdFusion application layer (in Java) and does not involve the database so you cannot use many of the functions that are available in the database.

Add a column to your qHistoryData query that calculates ROW_NUMBER() OVER( PARTITION BY collectid ORDER BY update_on DESC ) AS seqnum and then in your Query of Queries you can do:

<cfquery dbtype = "query">
SELECT *
FROM   qHistoryData
WHERE  seqnum = 1;
</cfquery>

Your other option is to manually process the query object and remove the unwanted rows.

Sign up to request clarification or add additional context in comments.

1 Comment

Given the data that OP already has, this is a good way to get the desired results. However, I still think this is probably data that can be returned from the original query without having to incur the overhead of a QoQ.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.