Mysql – Select columns across different databases

mysql

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

Best Solution

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