Query of Queries - Combining Two Datasources

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

  1. #1

    Default Query of Queries - Combining Two Datasources

    Problem: Query needs to combine fields from one datasource with those of
    another, matching on a common ID.

    Example:
    <CFQUERY DATASOURCE="Source1"
    SELECT * from Contacts
    </CFQUERY>

    join that to:
    <CFQUERY DATASOURCE="Source2"
    SELECT * from Companies
    </CFQUERY>

    Combine the data on a common CompanyID in each table (and different
    datasource) into records that show these fields:
    Name from Query 1
    Phone from Query 1
    Manager from Query 1
    Company Name from Query 2
    Company Address from Query 2

    IN ADDITION, the query needs to draw selection criteria from form fields such
    as:
    Where Manager = form field results (lives in first datasource)
    and Company name = other form field results (lives in first datasource)

    Thanks in advance for your help!

    storserver Guest

  2. Similar Questions and Discussions

    1. Query of Queries Combining Results
      I have a question related to query of queries and unions/joins. Below are my two queries and the output from them. What I need to do is join the...
    2. Running query with 2 datasources
      I have two databases that I need to pull data from. One database is application data the other has user info. The application data base has a list...
    3. Query of Queries on query New type query
      In CF5 we have a page that creates a query, using queryNew and querySetCell and the like, we then used dbtype="query" and gave it's name so we could...
    4. Combining Verity with Query of Queries
      Verity is capable of very powerful text searches and indexing, but it only returns Key, title, and decription. I'm working on an e-commerce site...
    5. How do I Query mulitple datasources?
      Here is what I have and what I need to do... 1. I have multiple dabases with financial transactions. All are based on the same table structure. ...
  3. #2

    Default Re: Query of Queries - Combining Two Datasources

    First, this might not work with select * in your original queries. You might
    have to type out the field names.

    the q of q is

    select q1.name, q1,phone,.. q2.companyname,...
    from q1, q2
    where q1.companyid = q2.companyid.

    To restrict your original queries to what you are getting from the form, use a
    where clause.

    Dan Bracuk Guest

  4. #3

    Default Re: Query of Queries - Combining Two Datasources

    to add to what Dan mentioned... If you
    want all items in q1 to be included, padding nulls in where
    q2 doesn't have a matching company use a LEFT OUTER join

    select q1.name, q1,phone,.. q2.companyname,...
    from q1 left outer join q2
    on q1.companyid = q2.companyid.

    If you want only the items in q1 that are also in q2,
    use an INNER or RIGHT INNER join (also may be
    a Natural Join)

    select q1.name, q1,phone,.. q2.companyname,...
    from q1 inner join q2
    on q1.companyid = q2.companyid.

    Check your db documentation, these joins are
    the same in theory, but SQL Server differs
    on the JOIN keyword than Oracle.... and such.

    --
    Tami
    aka DixieGal

    **************************
    So it is that the gods to dno give all men gifts of grace - neither good
    looks not intelligence nor eloquence...
    --Homer, The Odyssey
    **************************

    "Dan Bracuk" <webforumsuser@macromedia.com> wrote in message
    news:dj3his$fc5$1@forums.macromedia.com...
    | First, this might not work with select * in your original queries. You
    might
    | have to type out the field names.
    |
    | the q of q is
    |
    | select q1.name, q1,phone,.. q2.companyname,...
    | from q1, q2
    | where q1.companyid = q2.companyid.
    |
    | To restrict your original queries to what you are getting from the form,
    use a
    | where clause.
    |

    DixieGal Guest

  5. #4

    Default Re: Query of Queries - Combining Two Datasources

    Thank you for your help. I'd just add that I still got errors until I remembered to change
    <CFQUERY NAME="JoingTwoQueries" DATASOURCE="ABC">
    to:
    <CFQUERY NAME="JoingTwoQueries" DBTYPE="QUERY">

    storserver Guest

  6. #5

    Default Re: Query of Queries - Combining Two Datasources

    I was wrong. One more snag. Can you tell me why the Left Outer Join is erroring
    out as follows:

    Query Of Queries syntax error.
    Encountered "Left.

    Does the join work differenty when there's a DBTYPE="QUERY"?

    <CFQUERY NAME="JoinTwoQueries" DBTYPE="QUERY">
    SELECT Q1.CID, Q1.Company, Q2.Customer_ID, Q2.RCID
    FROM Q1 Left Outer Join Q2 on Q1.CID=Q2.Customer_ID
    </CFQUERY>

    storserver Guest

  7. #6

    Default Re: Query of Queries - Combining Two Datasources

    I searched Query of Queries in the help menu in Dreamweaver. It seems to say
    Left Outer Joins aren't possible with Queries of Queries. It says,
    Using joins
    A join operation uses a single SELECT statement to return a result set from
    multiple tables. The re are two main types of JOIN operations:

    INNER JOIN includes in the result set only records that are present in both
    tables
    OUTER JOIN includes in the result set all records in one of the tables.
    ColdFusion does not support OUTER JOINs, nor does it support the INNER JOIN
    syntax, as the following example shows:

    SELECT Dog_ID, Breed_ID,
    FROM Dogs INNER JOIN Breed
    ON Dogs.Dog_ID = Breed.Dog_ID;
    ColdFusion supports INNER JOINs between two tables, as the following example
    shows. This operation is the most common type of join.

    SELECT Dog_ID, Breed_ID
    FROM Dogs, Breed
    WHERE Dogs.Dog_ID = Breed.Dog_ID;


    Is there a way of doing left outer joins on QofQs?


    storserver Guest

  8. #7

    Default Re: Query of Queries - Combining Two Datasources

    I don't know that QofQ's support the JOIN syntax.

    [url]http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/using_39.htm#wp1175636[/url]
    mxstu Guest

  9. #8

    Default Re: Query of Queries - Combining Two Datasources

    Why are you attempting a left join anyway? Your original requirement
    was"Problem: Query needs to combine fields from one datasource with those of
    another, matching on a common ID." You don't need a left join to do that.



    Dan Bracuk Guest

  10. #9

    Default Re: Query of Queries - Combining Two Datasources

    You are right, Dan, my original request was only about Queries of Queries, not
    joins within them. DixieGal first mentioned the possibility of doing a left
    outer join and I realized that would give me the most flexibility. mxstu's
    response, "I don't know that QofQ's support the JOIN syntax." appears to be
    correct.

    Thanks for your help, everyone!

    storserver Guest

  11. #10

    Default Re: Query of Queries - Combining Two Datasources

    It is possible to produce a left join query using query functions, loops and
    ifs. It takes takes a bit more time, effort, thought, and keypounding than Q
    of Q.

    Originally posted by: storserver
    You are right, Dan, my original request was only about Queries of Queries, not
    joins within them. DixieGal first mentioned the possibility of doing a left
    outer join and I realized that would give me the most flexibility. mxstu's
    response, "I don't know that QofQ's support the JOIN syntax." appears to be
    correct.

    Thanks for your help, everyone!



    Dan Bracuk Guest

  12. #11

    Default Re: Query of Queries - Combining Two Datasources

    Originally posted by: storserver
    Problem: Query needs to combine fields from one datasource with those of
    another, matching on a common ID.

    Example:
    <CFQUERY DATASOURCE="Source1"
    SELECT * from Contacts
    </CFQUERY>

    join that to:
    <CFQUERY DATASOURCE="Source2"
    SELECT * from Companies
    </CFQUERY>

    Combine the data on a common CompanyID in each table (and different
    datasource) into records that show these fields:
    Name from Query 1
    Phone from Query 1
    Manager from Query 1
    Company Name from Query 2
    Company Address from Query 2

    IN ADDITION, the query needs to draw selection criteria from form fields such
    as:
    Where Manager = form field results (lives in first datasource)
    and Company name = other form field results (lives in first datasource)

    Thanks in advance for your help!



    DMM_ENT Guest

  13. #12

    Default Re: Query of Queries - Combining Two Datasources

    Originally posted by: storserver
    Problem: Query needs to combine fields from one datasource with those of
    another, matching on a common ID.

    Example:
    <CFQUERY DATASOURCE="Source1"
    SELECT * from Contacts
    </CFQUERY>

    join that to:
    <CFQUERY DATASOURCE="Source2"
    SELECT * from Companies
    </CFQUERY>

    Combine the data on a common CompanyID in each table (and different
    datasource) into records that show these fields:
    Name from Query 1
    Phone from Query 1
    Manager from Query 1
    Company Name from Query 2
    Company Address from Query 2

    IN ADDITION, the query needs to draw selection criteria from form fields such
    as:
    Where Manager = form field results (lives in first datasource)
    and Company name = other form field results (lives in first datasource)

    Thanks in advance for your help!


    HI, there!

    I have one question, yet it is off the subject matter. I simply need some
    advise.
    I am developing one company presentation that will be run from a CD. This
    presentation will be completely done in Flash.
    Because it will contain a lot of written info, I want to connect it with some
    database.
    I don't know how I can create a Flash presentation that communicates with a
    database, run search queries, and updates data and still be fully operational
    from a normal CD (without the need to use a web server).

    DMM_ENT 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