473,382 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Single query of multiple external databases?

ats
I have a table that contains the database names of external databases.
Each one of these external databases contain a table (which has the
same structure) that I would like to query together as one list.

For example, say each external db has a table of names.

tbNames (external db structure)
-------
name as text
- example db1.mdb
John Doe
Jane Doe
Alan Smith

- example db2.mdb
Jim Jackson
Jack Lane
Peter North

- example db3.mdb
Kim Lane
Mike Arnet
Mat Smith

tbDBName
--------
dbName as text
- example:
c:\db1.mdb
c:\db2.mdb
c:\db3.mdb

How do you query all of these external tables together to form a
complete list?
Desired example query results:
John Doe
Jane Doe
Alan Smith
Jim Jackson
Jack Lane
Peter North
Kim Lane
Mike Arnet
Mat Smith

Nov 13 '05 #1
6 9590
You would use a union query to compile them together into a single list, and
you'd use "IN" to specify an external database --

select name from tbNames in c:\db1.mdb
union select name from tbName in c:\db2.mdb....

If your database names are stored in a table, then you'll need to generate
your SQL in code, looping through the list of names to create the SQL.

Neil
"ats" <at*@MariettaScientific.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a table that contains the database names of external databases.
Each one of these external databases contain a table (which has the
same structure) that I would like to query together as one list.

For example, say each external db has a table of names.

tbNames (external db structure)
-------
name as text
- example db1.mdb
John Doe
Jane Doe
Alan Smith

- example db2.mdb
Jim Jackson
Jack Lane
Peter North

- example db3.mdb
Kim Lane
Mike Arnet
Mat Smith

tbDBName
--------
dbName as text
- example:
c:\db1.mdb
c:\db2.mdb
c:\db3.mdb

How do you query all of these external tables together to form a
complete list?
Desired example query results:
John Doe
Jane Doe
Alan Smith
Jim Jackson
Jack Lane
Peter North
Kim Lane
Mike Arnet
Mat Smith

Nov 13 '05 #2
ATS,
The other poster got it pretty much right. Here is some sample SQL that
with changes to reflect your database should work:
--Pull people names from the first database
"SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB1.MDB'

--Now the second database.
UNION SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB2.MDB'"

If the source tables don't change you can create this once and every time
you run it you will get whatever is in the source tables.

"ats" <at*@MariettaScientific.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a table that contains the database names of external databases.
Each one of these external databases contain a table (which has the
same structure) that I would like to query together as one list.

For example, say each external db has a table of names.

tbNames (external db structure)
-------
name as text
- example db1.mdb
John Doe
Jane Doe
Alan Smith

- example db2.mdb
Jim Jackson
Jack Lane
Peter North

- example db3.mdb
Kim Lane
Mike Arnet
Mat Smith

tbDBName
--------
dbName as text
- example:
c:\db1.mdb
c:\db2.mdb
c:\db3.mdb

How do you query all of these external tables together to form a
complete list?
Desired example query results:
John Doe
Jane Doe
Alan Smith
Jim Jackson
Jack Lane
Peter North
Kim Lane
Mike Arnet
Mat Smith

Nov 13 '05 #3
ATS,
The other poster got it pretty much right. Here is some sample SQL that
with changes to reflect your database should work:
--Pull people names from the first database
"SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB1.MDB'

--Now the second database.
UNION SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB2.MDB'"

If the source tables don't change you can create this once and every time
you run it you will get whatever is in the source tables.

"ats" <at*@MariettaScientific.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a table that contains the database names of external databases.
Each one of these external databases contain a table (which has the
same structure) that I would like to query together as one list.

For example, say each external db has a table of names.

tbNames (external db structure)
-------
name as text
- example db1.mdb
John Doe
Jane Doe
Alan Smith

- example db2.mdb
Jim Jackson
Jack Lane
Peter North

- example db3.mdb
Kim Lane
Mike Arnet
Mat Smith

tbDBName
--------
dbName as text
- example:
c:\db1.mdb
c:\db2.mdb
c:\db3.mdb

How do you query all of these external tables together to form a
complete list?
Desired example query results:
John Doe
Jane Doe
Alan Smith
Jim Jackson
Jack Lane
Peter North
Kim Lane
Mike Arnet
Mat Smith

Nov 13 '05 #4
ats
Thanks to all, but this doesn't address the file names in a table. The
given solutions work fine for predefined databases, but if you had a
whole table of entries that change... The only way I've found was using
VBA to create the SQL getting the entries from the table and making the
UNION. I guess I was looking for a single query that could do the same.

Nov 13 '05 #5
That's what I said -- "If your database names are stored in a table, then
you'll need to generate
your SQL in code, looping through the list of names to create the SQL."
Using VBA is the only way you can do it. But, once it's written, it should
be very simple to execute. Just have your code get the querydef of the query
you want to use, apply your generated SQL to the query, and then open the
query. Pretty simple.

Neil

"ats" <at*@MariettaScientific.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
Thanks to all, but this doesn't address the file names in a table. The
given solutions work fine for predefined databases, but if you had a
whole table of entries that change... The only way I've found was using
VBA to create the SQL getting the entries from the table and making the
UNION. I guess I was looking for a single query that could do the same.

Nov 13 '05 #6
Actually, in Access the table alias isn't necessary. But, you're right, I
did forget the single quotes around the database filename.

Neil

"Alan Webb" <kn*****@hotmail.com> wrote in message
news:L6********************@comcast.com...
ATS,
The other poster got it pretty much right. Here is some sample SQL that
with changes to reflect your database should work:
--Pull people names from the first database
"SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB1.MDB'

--Now the second database.
UNION SELECT PERSON.NAME FROM
PERSON_TBL AS PERSON IN 'C:\DOCUMENTS AND SETTINGS\SOMEGEEK\MY
DOCUMENTS\DB2.MDB'"

If the source tables don't change you can create this once and every time
you run it you will get whatever is in the source tables.

"ats" <at*@MariettaScientific.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
I have a table that contains the database names of external databases.
Each one of these external databases contain a table (which has the
same structure) that I would like to query together as one list.

For example, say each external db has a table of names.

tbNames (external db structure)
-------
name as text
- example db1.mdb
John Doe
Jane Doe
Alan Smith

- example db2.mdb
Jim Jackson
Jack Lane
Peter North

- example db3.mdb
Kim Lane
Mike Arnet
Mat Smith

tbDBName
--------
dbName as text
- example:
c:\db1.mdb
c:\db2.mdb
c:\db3.mdb

How do you query all of these external tables together to form a
complete list?
Desired example query results:
John Doe
Jane Doe
Alan Smith
Jim Jackson
Jack Lane
Peter North
Kim Lane
Mike Arnet
Mat Smith


Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
0
by: sean peters | last post by:
Hi all, i've been weighing the pros and cons of running multiple concurrent mysqld's on one server, to have better control over what databases are on what physical disks. System: 4 processor sun...
0
by: Dave | last post by:
Hi all, I have a problem with a query. (well, I actually have a few problems...) Here is my query. select FOCUS.SiteName, FOCUS.URL, OTWAdCars.* , REGION.SiteName as RegionSite, REGION.URL...
3
by: G rumpy O ld D uffer | last post by:
This is probably a 'Low-Level' question to all the ACCESS experts but I've only been using ACCESS for a couple of weeks. I've been given 30+ (and counting) separate 'Weekly' Databases which all...
7
by: Daz | last post by:
Hi. I am trying to select data from two separate MySQL tables, where I cannot use join, but when I put the two select queries into a single query, I get an error telling me to check my syntax. Both...
0
by: rkreddys | last post by:
Tasks to Move SQL 2000 Databases into Single Server with multiple dabases then Upgrade SQL 2000 to 2005 and Merge multiple databases into single database. How to move Databases over WAN links...
12
by: bhipwell via AccessMonster.com | last post by:
Hello, I have hit the "Cannot open any more databases" and "System resource exceeded" errors. Knew this was coming, but as I got closer to finishing the database, I hoped it wouldn't be an...
1
by: cvalarmathi | last post by:
Hi Friends, How to drop all databases in one query.I don't know.If anybody know the answer please reply me.....
4
by: JoyceBabu | last post by:
Can anyone plz tell me the advantages and disadvantages of using multiple databases / single database for all tables. I have a site with more than a 100 tables. Current all the tables are in a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.