Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select columns across different databases

Tags:

mysql

Is it possible to do a select ( or insert) statement across different databases that are located on the same server? If yes, how?

like image 595
Graviton Avatar asked Mar 23 '09 16:03

Graviton


People also ask

Can you query from multiple databases?

It is possible to use SQL to write one query that combines the information from many databases. There are two requirements: You must prefix all table references with the database name (e.g. customers.

How do you run a SQL query across multiple databases with one query?

Open a new Query Window and write a query which has to be executed against multiple database of a server. Right click in the window and Select an option “Run On Multiple Targets” as shown below. This will open a new window which will have all the database available on the current server listed as shown below.


1 Answers

You would specify the database by using the syntax databasename.tablename

Example:

SELECT      mydatabase1.tblUsers.UserID,      mydatabse2.tblUsers.UserID FROM     mydatabase1.tblUsers        INNER JOIN mydatabase2.tblUsers             ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID 
like image 197
TheTXI Avatar answered Sep 23 '22 11:09

TheTXI