Joining records from 2 datasources

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

  1. #1

    Default Joining records from 2 datasources

    Can it be done. I am getting userIDs from one database and I need to show the
    records those userIDs correspond to from the other database. The DBs are on
    differnet datasources.

    Right now I am creating a list of userIDs and doing this:

    SELECT * FROM database1..table1
    WHERE userID in (#userIDlist#)

    I would rather do:
    SELECT * FROM database1..table1
    WHERE userID in (SELECT userID FROM database2..table2)

    Thx for any help.


    chexonec Guest

  2. Similar Questions and Discussions

    1. Verifying datasources
      Hi, everyone. I didn't write anything for a while. I have an interesting situation here and not sure what causes it and what exactly is the...
    2. Use CF Datasources outside CF
      I need to create a JSP on the coldfusion server, and access coldfusion datasources in that JSP. Is there anyway to do this in CF6.1 or CF7. ...
    3. CF5 Datasources missing
      :confused; Hi folks, I was wondering if anyone can help. My datasources have gone missing in CF5 Administrator, and now my apps refuse to work....
    4. accessing two different datasources
      I need to connect to 2 dfferent datasources that are in two different servers. Example: I need to move data from one table on server 1to a table...
    5. Joining Paths or joining two shapes
      Hi, I have drawn threeleaves with the pen tool (closed paths). I would like to join these leaves to make a flower into which I want to place an...
  3. #2

    Default Re: Joining records from 2 datasources

    What database(s) are you using? Are the databases on the same server?
    mxstu Guest

  4. #3

    Default Re: Joining records from 2 datasources

    Sorry, each query within CFQUERY tags can only be performed on a single
    datasource.

    The way you're doing it is probably the best solution for a small list. BUT if
    you are talking about a long list of ID values Oracle will have a problem when
    it gets to 1000 and the speed isn't too great on long lists for any database.
    You could try using QoQ which will look like a silly method, but will work.

    Query on DS1 named DS1query

    Query on DS2 named DS2query

    SELET *
    FROM DS1query
    WHERE ID IN (SELECT ID FROM DS2query)


    Another alternative is to write a Stored Procedure for it as they can access
    data from other databases, the Stored Procedure can then be called from CF.

    HTH

    Zoe

    zoeski80 Guest

  5. #4

    Default Re: Joining records from 2 datasources

    Most enterprise level databases allow you to reference other databases or link
    to other database servers. With the correct permissions, you should then be
    able reference both database objects in the same cfquery.



    mxstu Guest

  6. #5

    Default Re: Joining records from 2 datasources

    Most enterprise level databases allow you to reference other databases or link
    to other database servers. With the correct permissions, you should then be
    able reference both database objects in the same cfquery.



    mxstu Guest

  7. #6

    Default Re: Joining records from 2 datasources

    mxtu is right. At least in Oracle we use 2 sources when needed.
    For example, if you (your DBA) granted SELECT permission for table1 in
    database1 for users of database2 your query could look like this (supposed your
    DSN provides connection to database2):
    SELECT * FROM database1.table1
    WHERE userID in (SELECT userID FROM table2).
    OR
    If you granted SELECT permission for table2 in database2 for users of
    database1 your query will look (supposed your DSN provides connection to
    database1):
    SELECT * FROM table1
    WHERE userID in (SELECT userID FROM database2.table2).



    CF_Oracle Guest

  8. #7

    Default Re: Joining records from 2 datasources

    did you try to use a inner join?

    jorgepino Guest

  9. #8

    Default Re: Joining records from 2 datasources

    Two options. I've accomplished it either way, just depends on the situation.

    1. Use a query of queries. Query one, select your data from datasource 1. Then
    select your data from datasource 2. Use a query of query for the 3rd query and
    join with the result set from both. Could use queryaddColumn() within this.

    2. Simpler approach. Setup a scheduled task to dump the data from your
    datasource into the other datasource nightly. This depends a lot on your
    situation. I've done this when it makes sense. I recently had a instance where
    I was generating some substantial reports and doing the nightly task vs the
    joining on another datasource just was much more efficient, as processing time
    needed to be optimal.

    Hope this helps,
    Shane

    dj shane Guest

  10. #9

    Default Re: Joining records from 2 datasources

    dj shane,

    Why pull all the information across or use separate queries? Doesn't your database support referencing other databases/linking servers?




    mxstu 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