Skip to main content
Participant
Oct 15, 2019 6:55 AM UTC
Question

Selecting a row range from query of queries

Hi, is there a way to select a row range from query of query. I mean like an alternative for LIMIT and OFFSET in regular MySQL queries.

    This topic is closed to new replies. Start a new post to keep the conversation going.

    3 replies

    Participating Frequently
    Oct 16, 2019 8:36 PM UTC

    Depending on the underlying database you are using it is possible. In SQL Server, and I think My SQL, you can use the ROW_NUMBER() function to generate an incrementing sequence number for each row in the result set.

     

    <cfquery name="q" datasource="DSN">
    SELECT col1, col2,
    ROW_NUMBER() OVER (ORDER BY col1) AS rownum
    FROM myTable
    </cfquery>

    <cfquery name="qq" dbtype="query">
    SELECT col1, col2, rownum
    from q
    where rownum between 20 and 30
    </cfquery>

    Translate
    BKBK
    Community Expert
    Community Expert
    Oct 16, 2019 7:33 PM UTC

    Query of query doesn't have that. Nevertheless, if your query had a numerically ordered column, then you could filter using a clause like:

    where productId between 27 and 89 

     

    Translate
    WolfShade
    Legend
    Oct 15, 2019 12:52 PM UTC

    According to the QoQ Help page, no.

     

    V/r,

     

    ^ _ ^

    Translate