Link to home
Start Free TrialLog 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
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of danjen
danjen

ASKER

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

Thanks!