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

  1. #1

    Default Help with CF_Tag

    Is there a way to combine the following queries into one query so that I can
    use a single query with CF_TwoSelectsRelated?
    Or a way to use 2 queries with CF_TwoSelectsRelated?

    <CFQUERY DATASOURCE="DB" NAME="cats">
    SELECT *
    FROM itemParentCats
    ORDER BY itemParentCatID
    </CFQUERY>

    <CFQUERY DATASOURCE="DB" NAME="subcats">
    SELECT *
    FROM itemCats
    WHERE itemParentCatID= '#cats.itemParentCatID#'
    ORDER BY itemCatID
    </CFQUERY>

    Any insight would be greatly appreciated.

    *thirtysixsquares* Guest

  2. #2

    Default Help with CF_Tag

    Is there a way to combine the following queries into one query so that I can
    use a single query with CF_TwoSelectsRelated?
    Or a way to use 2 queries with CF_TwoSelectsRelated?

    <CFQUERY DATASOURCE="DB" NAME="cats">
    SELECT *
    FROM itemParentCats
    ORDER BY itemParentCatID
    </CFQUERY>

    <CFQUERY DATASOURCE="DB" NAME="subcats">
    SELECT *
    FROM itemCats
    WHERE itemParentCatID= '#cats.itemParentCatID#'
    ORDER BY itemCatID
    </CFQUERY>

    Any insight would be greatly appreciated.

    *thirtysixsquares* Guest

  3. #3

    Default Re: Help with CF_Tag

    Hi

    i think its better to post your requirement than posting your queries. so that we can understand better.

    vkunirs Guest

  4. #4

    Default Re: Help with CF_Tag

    Requirements:
    Use 2 queries with CF_TwoSelectsRelated

    OR

    Combine the 2 queries mentioned previously in order to offer 1 query to CF_Tag
    *thirtysixsquares* Guest

  5. #5

    Default Re: Help with CF_Tag

    CF_2SR is made for this, that is, you need to join the two queries to get the
    tag to work the way you want it to work. So, <CFQUERY DATASOURCE='DB'
    NAME='cats'> SELECT * FROM itemParentCats ORDER BY itemParentCatID </CFQUERY>
    <CFQUERY DATASOURCE='DB' NAME='subcats'> SELECT * FROM itemCats WHERE
    itemParentCatID= '#cats.itemParentCatID#' ORDER BY itemCatID </CFQUERY>
    becomes SELECT * FROM itemParentCats pcats JOIN ItemCats cats on
    cats.itemParentCatID= pcats.itemParentCatID ORDER BY itemParentCatID I don't
    think you need both key fields. It's bad form to have them both named the
    same, since you have to designate one field as the key for the tag to work
    properly. Specify the fields you want back. You should never, as a rule, use
    SELECT *. HTH,

    philh Guest

  6. #6

    Default Re: Help with CF_Tag

    Man, the edit function on this forum sucks.
    philh Guest

  7. #7

    Default Re: Help with CF_Tag

    I don't understand the cat and pcat after the FROM.
    Is there a way you could elaborate?

    Thx
    *thirtysixsquares* Guest

  8. #8

    Default Re: Help with CF_Tag

    Because you are joining two tables by columns with the same name, you can
    "alias" the table names to a shorter value and use that as the prefix on the
    column name, or you can use the full table name in your join.

    SELECT *
    FROM itemParentCats pcats
    JOIN ItemCats cats on cats.itemParentCatID= pcats.itemParentCatID
    ORDER BY itemParentCatID

    is the same as...

    SELECT *
    FROM itemParentCats
    JOIN ItemCats on ItemCats.itemParentCatID= itemParentCats.itemParentCatID
    ORDER BY itemParentCatID

    Using table name aliases become mandatory when doing a self join (joining the
    same table to itself).

    Phil

    paross1 Guest

  9. #9

    Default Re: Help with CF_Tag

    The Query throws an error at the FROM line in both methods.
    *thirtysixsquares* Guest

  10. #10

    Default Re: Help with CF_Tag

    1. What is the error?
    2. What is your database?

    Perhaps.....

    <CFQUERY DATASOURCE="DB" NAME="cats">
    SELECT *
    FROM itemParentCats p, itemCats c
    WHERE p.itemParentCatID = c.itemParentCatID
    ORDER BY itemParentCatID
    </CFQUERY>

    Phil

    paross1 Guest

  11. #11

    Default Re: Help with CF_Tag

    ERRORS:
    Well at one point I was getting "Data type mismatch"
    Now all I seem to get is "The specified field 'itemParentCatID' could refer to
    more than one table listed in the FROM clause of your SQL statement. "

    It would probably make life easier if the parent cats and the subcats were
    just in one table, eh?
    I suppose there's still time to do this, but is it necessary?

    *thirtysixsquares* Guest

  12. #12

    Default Re: Help with CF_Tag

    I have pulled them into one table. Now each category record has one itemCatID
    (one itemCatName) and one itemParentCatID. The itemParentCatID refers to the
    itemCatID of another record in the same table. EX:
    1 First Main Category 0
    2 Subcategory 1
    3 Second Main Category 0
    2 Subcategory 3

    MS Access DB

    The first drop down should report the itemCatName (name=maincat
    value=itemCatID) WHERE itemParentCatID = 0
    Which should then populate the second dropdown with itemCatName (name=subcat
    value=itemCatID) WHERE itemParentCatID = maincat.itemParentCatID

    Does this make the query more clear, to do it all in one table?

    Thank you so much for your help, Phil.

    *thirtysixsquares* Guest

  13. #13

    Default Re: Help with CF_Tag

    The reason that you are getting the error The specified field 'itemParentCatID'
    is because you are doing a SELECT * from both tables, and each has a column
    with the same name. You should select distinct column names instead of using
    the * wildcard, adding the prefix of the table alias or full table name to each
    column name selected in order to eliminate ambiguity.

    As for your combined table, sorry, it makes no sense to me, but if you can get
    what you need by combining both, without de-normalizing the data, then go for
    it.

    Phil

    paross1 Guest

  14. #14

    Default Re: Help with CF_Tag

    Okay...the query's working
    the two selects show the cats...and almost work

    The parent cats display fine, but don't submit to the action page
    The sub cats display the subs of the first parent cat but don't "refresh" to
    another set of subcats if the parent cat select is changed

    Any ideas??

    *thirtysixsquares* 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