The mechanics of CFQUERY

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default The mechanics of CFQUERY

    I inherited a query (shown below) that is going against a DB2 table with over
    600,000 rows. Note there is no WHERE clause. I'm puzzled as to what the
    author intended, but my curent question is this: Does ColdFusion tell DB2 to
    return only 1 row? If so, which one? If not, does the query retrieve A, B
    and C from all 600,000+ rows?



    <cfquery dbtype="query" name="MFC2" maxrows="1">
    SELECT A, B, C FROM orderTable
    </cfquery>

    jdeline Guest

  2. Similar Questions and Discussions

    1. cfquery bug...still?
      Hi, I have ColdFusion MX7,0,0,91690. I am trying to utilize the attached code. I am passing the query (it's easier for my implementation) in a...
    2. cfquery
      I am trying to use debug in a query and it is a no go(should show at bottom of page). the query is working because I am getting recordcounts. Then...
    3. Output from Cfquery
      I have some pl/sql I want to run in my cfquery. I'd like to get the output from the cfquery The cfquery is calling a function. <cfquery...
    4. need help with cfquery
      This should be an easy one ... unfortunately I am a n00b to sql and CF. I am trying to display a certain column in a table, the most recent one. I...
    5. CFQUERY with IF THEN ELSE
      I have a CFQUERY which works perfectly and now I would like to add a little date calculation to this query to filter it little more. The query is a...
  3. #2

    Default Re: The mechanics of CFQUERY

    From what I understand, using maxrows sends the statement to the database as
    is. So the database selects all 600K records from the table. ColdFusion then
    reads the results until it reaches the specified number of rows (in this case 1
    record). You're right in thinking that using the database to limit the
    records would be more efficient. Like ....

    SELECT TOP 1 A, B, C FROM orderTable

    ... or ...

    SELECT A, B, C FROM orderTable LIMIT 1

    The database would then only select and return (1) record.

    mxstu Guest

  4. #3

    Default Re: The mechanics of CFQUERY

    I looked at that query again, and duh!, it is not using a datasource, it has
    dbtype="query". The 600,000+ record had previously been SELECTed by a query
    named MFC2 that did have a WHERE clause. So the query in question is not
    retrieving the world after all.

    There remains the question: What was the author trying to do by running a
    query on an existing recordset?

    jdeline Guest

  5. #4

    Default Re: The mechanics of CFQUERY

    Yes, I missed the "dbtype" as well. I guess they are using maxrows because
    QofQ has no "TOP" or "LIMIT" operator, afaik.

    What are they using the query for? Perhaps that will give you an idea why the
    only want (1) row?

    mxstu Guest

  6. #5

    Default Re: The mechanics of CFQUERY

    > What are they using the query for? Perhaps that will give you an idea why they only want (1) row?

    I'm looking into that today. Thanks for your help.

    jdeline Guest

  7. #6

    Default Re: The mechanics of CFQUERY

    No problem. Good Luck!
    mxstu Guest

  8. #7

    Default Re: The mechanics of CFQUERY

    if you wish DB2 to return N rows, where N is an integer
    use this type of SQL and don't use the maxrow option of the cfquery tag

    select * from YOUR_TABLE
    where YOUR_CONDITION
    order by YOUR_CHOICE
    Fetch first N rows only

    (note that if you only 1 row you use row or rows in the fetch line)

    jmich Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139