472,328 Members | 1,629 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,328 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 9503
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...
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...
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,...
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...
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,...
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...
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...
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...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
1
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

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.