473,385 Members | 1,693 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,385 software developers and data experts.

multiple database select

Hi,

How do I at the best way perform select statements over multiple
databases?

I have a couple of databases containing the same table definitions with
diffrent data. Now I want them to act as a single database giving me
one answer on a select statement but the answer fetched from all my
defined databases.

Right now the databases are on the same node and I guess it is possible
to do something like:
select * from db1.table1, db2.table1 etc etc. but I really do not want
to modify all my sql statements if another database would comes into
picture or is revoved from the set.

One solution may be to create a view?!
I am using PHP and PEAR DB to access and query my databases.

thanks,

Karolina

Jun 16 '06 #1
3 8680
>How do I at the best way perform select statements over multiple
databases?


If you're talking about different databases handled by the same
server, you can use the databasename.tablename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt
Jun 16 '06 #2

Gordon Burditt skrev:
How do I at the best way perform select statements over multiple
databases?


If you're talking about different databases handled by the same
server, you can use the databasename.tablename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt


Hi,

yes, I may use db1.table1, db2.table approach since all my databases
are on the same node at the moment. Still, I want to transparantly be
able to add or remove databases from the set without changing the
specific sql statements refering to the table.

thanks,

karolina

Jun 16 '06 #3
>> >How do I at the best way perform select statements over multiple
>databases?


If you're talking about different databases handled by the same
server, you can use the databasename.tablename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt


Hi,

yes, I may use db1.table1, db2.table approach since all my databases
are on the same node at the moment. Still, I want to transparantly be
able to add or remove databases from the set without changing the
specific sql statements refering to the table.


You have to tell it where the tables are. You are stuck with that.

Why are all the tables in different databases?

You might be able to refer to the table as $database_of_table1.table1
and let PHP substitute it, but there's got to be a file somewhere
you have to change if you move a table. You could also create a
federated table that points at the actual location of the table,
and re-create it if the actual table moves.

I suppose you could do something like selecting from
INFORMATION_SCHEMA.TABLES to figure out which databases have tables
named 'foo', and then try to figure out which one you should use.
(Requires MySQL 5.0 or greater, doesn't work across multiple servers,
and doesn't really solve the problem anyway).

I don't know of any way to *REMOVE* a table (vs. moving it elsewhere)
without affecting a SQL statement that uses it.

I don't know of any way to *ADD* a table to a SQL statement (presumably
a join) without affecting the SQL statement.

The best way I have found to keep databases out of the SQL is to
put all the tables in the same database, and use an include file
which defines the variables $mysql_server, $mysql_user, $mysql_password,
and $mysql_db, which I can change for the application without
changing the rest of the page. The application sets the current
database once and never changes it.

If for some reason I can't put all the tables in the same database
I usually end up using two connections (potentially on different
servers) with two sets of these. This approach does not scale very
well, and you can't do joins between tables on different connections.

Gordon L. Burditt
Jun 16 '06 #4

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

Similar topics

3
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection...
6
by: Don Leverton | last post by:
Hi All, I've got a situation where I am developing an Access 97 app for a client, and am in the "beta testing" stage. I have split the app up, using the DB splitter, into front-end /back-end...
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
4
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure...
12
by: Peter Proost | last post by:
Hi group, has anyone got any suggestions fot the best way to handle this problem, I've got 3 tables for example table A, B, and C table A looks like name, value table B looks like name, value...
0
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
7
by: ozzii | last post by:
Hi I have a HTML form with a multiple select box. The multiple select box is populated from a database. A user can select multiple options form this select box and the infomrtaion is then stored...
2
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql...
3
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.