Ask a Question related to Coldfusion Database Access, Design and Development.
-
Naim Kamel #1
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
-
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... -
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? -
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... -
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... -
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, -
MikerRoo #2
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
-
Naim Kamel #3
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
-
Naim Kamel #4
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
-
Naim Kamel #5
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



Reply With Quote

