Link to home
Create AccountLog in
Avatar of danjen
danjen

asked on

Is is possible to create a single query that accesses two databases in MYSQL

Hi Experts-

I am hoping someone can tell me if this is possible.

I am running multiple websites for a common industry. Much of the product information is the same. I would like to have 1 database that accesses all of the product information and a separate database for each client that manages the brands they carry and the prices. Is it possible to create a single query that accesses both of these databases? The query would need to access the product information from one database and the pricing from another. I am not looking to do a union. That wouldn't work.

Thanks for your help.
Avatar of johanntagle
johanntagle
Flag of Philippines image

Assuming both databases are on the same machine, according to this you can:

http://www.dottedidesign.com/node/14

Basically you access the tables via database_name.table_name and the columns via database_name.table_name.column_name.  Then just do your usual SQL joins.  
ASKER CERTIFIED SOLUTION
Avatar of wolfgang_93
wolfgang_93
Flag of Canada image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of danjen
danjen

ASKER

Both of your answers were helpful and I was able to achieve the result I needed.

Thanks!