SQL select information from two databases

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

  1. #1

    Default SQL select information from two databases

    Hi
    I'm working on a ColdFusion project that has more than 8 diffrent data sources.
    I'm trying to select the information inside a table called Latesnews.
    This table has the same structure in all the 8 datasources.
    Now, how can i list all of them in one page and sort them according to the
    date or something?


    Naim Kamel Guest

  2. Similar Questions and Discussions

    1. Outputting information from relational databases
      Hello, This is the issue at hand, I have a relational database. Two of the tables are in a relationship, I have a query that allows a person to...
    2. How do I query third-party public information databases.
      I read an article on Wired.com about "Zabasearch" and wanted to know how are they writing queries that go to the courts, dmv, etc?
    3. doing a select across databases
      Is there a way in db2 to select from a table that is on a remote database. I guess my question is how do I fully qualify the name of the table that...
    4. Federated Databases, joins across databases etc
      Greetings, I want to do a join between 2 tables on 2 different db2 databases on the same server. I assume that I have to use federated databases. I...
    5. SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
      Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id,
  3. #2

    Default RE: SQL select information from two databases

    If you have a high end data base like SQL server or Oracle, it is more
    efficient to do this kind of thing using their tools (if you can).

    The attached code shows the gist of doing it all in Coldfusion.

    If the tables really do have identical structures and names, you can just loop
    though the same query 8 times, changing the query name and data source at each
    pass.
    I showed duplicate code, just in case.



    <CFQUERY name="qNewsSource1" datasource="DATA_SOURCE_1">
    SELECT
    StoryHeadline
    , StoryText
    , StoryDate
    FROM
    Latesnews
    WHERE
    ...Whatever ...
    </CFQUERY>

    <CFQUERY name="qNewsSource2" datasource="DATA_SOURCE_2">
    SELECT
    StoryHeadline
    , StoryText
    , StoryDate
    FROM
    Latesnews
    WHERE
    ...Whatever ...
    </CFQUERY>


    ... ETC, ETC, ...


    <CFQUERY name="qNewsSource8" datasource="DATA_SOURCE_8">
    SELECT
    StoryHeadline
    , StoryText
    , StoryDate
    FROM
    Latesnews
    WHERE
    ...Whatever ...
    </CFQUERY>


    <!--- Now put all the datasources together. If their are duplicates, change
    the "union all"
    Statements to just "union" -- but this can be quite a bit slower.
    --->

    <!--- Use a query of queries --->

    <CFQUERY name="qALL_NewsStories" dbtype="query"> <!--- Note, no datasource
    --->

    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource1
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource2
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource3
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource4
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource5
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource6
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource7
    UNION ALL
    SELECT StoryHeadline, StoryText, StoryDate FROM qNewsSource8

    ORDER BY
    StoryDate DESC,
    StoryHeadline
    </CFQUERY>

    MikerRoo Guest

  4. #3

    Default Re: SQL select information from two databases

    nice idea.
    Since i'm using Access here is what another friend told me.
    In access they have the link table thing. so i liked all the tables into the
    main database and used the union thing.
    Both ways works but i have to test which is quicker.

    Naim Kamel Guest

  5. #4

    Default Re: SQL select information from two databases

    nice idea.
    Since i'm using Access here is what another friend told me.
    In access they have the link table thing. so i liked all the tables into the
    main database and used the union thing.
    Both ways works but i have to test which is quicker.

    Naim Kamel Guest

  6. #5

    Default Re: SQL select information from two databases

    nice idea.
    Since i'm using Access here is what another friend told me.
    In access they have the link table thing. so i liked all the tables into the
    main database and used the union thing.
    Both ways works but i have to test which is quicker.

    Naim Kamel 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