CF Multiple Queries, Multiple Records

Ask a Question related to Macromedia ColdFusion, Design and Development.

  1. #1

    Default CF Multiple Queries, Multiple Records

    All,

    I've got three queries all passing variables from previous queries. The
    issues?
    The second query returns 4 records. I want to use IDs for these records in
    query #3.
    However what I have only returns only 1 record. I want all 4 ID values in
    query #3

    <!-- GET EVERYTHING FROM CATEGORIES -->
    <!-- QUERY ONE -->
    <cfquery name="cats" datasource="cfweb" maxrows="5">
    SELECT Categories.Name, Categories.Category_ID
    FROM Categories
    </cfquery>
    <!-- GET INFO FROM PRODCAT WHERE CATID = CATS.CATID THIS SHOULD RETURN A LIST
    OF PROD IDS -->
    <!-- QUERY TWO -->
    <cfquery name="PRODCAT" datasource="cfweb">
    SELECT ID, Product_ID, Category_ID
    FROM Product_Category
    WHERE Category_ID = #CATS.Category_ID#
    </cfquery>
    <cfquery name="PROD" datasource="cfweb">
    SELECT NAME
    FROM Products
    WHERE Product_ID = #PRODCAT.Product_ID#

    Thanks

    D

    OnDemand Junkie Guest

  2. Similar Questions and Discussions

    1. multiple queries and cfgrid
      Hi, I have a soccer(futbol, for some of you folks) standings page. I have it all working perfectly within a standard html page just fine. I want to...
    2. multiple queries in a cfmail tag ?
      How can you create multiple queries in a cfmail tag ? Anyone?
    3. Multiple DSN queries
      I can easily query multiple DSNs in the same CF query, using CFMX 6.1 and win 2000. Unfortunately i am unable to perform the same query on a win2003...
    4. update multiple records in multiple tables from one form
      hello I have been trying to run multiple update queries based on the data entered by user. Brief background: I am fetching data from various...
    5. posting multiple queries
      This is puzzling. If I run $sql = "INSERT INTO customer...
  3. #2

    Default Re: CF Multiple Queries, Multiple Records

    You can use the CF ValueList() function to create a comma delimited list of all
    IDs returned by the previous query. Then use the SQL IN() function to return
    all records where the column value equals any one of the IDs in the returned
    list.

    Do you need to keep the data in separate queries? You could probalby combine
    your 3 query statements into 1.

    <!--- needs error handling - ex. if "PRODCAT" query returns 0 records --->
    SELECT Name
    FROM Products
    WHERE Product_ID IN (#ValueList(PRODCAT.Product_ID)#)

    mxstu Guest

  4. #3

    Default Re: CF Multiple Queries, Multiple Records

    Hi

    Assuming you don't need all three queries, you could do something like this

    SELECT
    Cat.Name, Cat.Category_ID ,
    prodcat.ID, prodcat.Product_ID, prodcat.Category_ID,
    prod.NAME
    FROM
    Categories cat,
    Product_Category prodcat,
    Products prod
    Where
    prodcat.Category_ID = cat.Category_ID and
    prod.Product_ID = prodcat.Product_ID

    stephend 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