Join Tables Across Different Databases

Joining tables in queries across different MySQL databases is possible if you use fully qualified database and table names.

Both databases will need to be on the same server for this to work ;)

SELECT  db1.table1.column1,
        db2.table1.column1
FROM    db1.table1 LEFT JOIN db2.table1
        ON
          (
            db1.table1.column2 = db2.table1.column2
          );

The example query will pull two columns (column1 from both databases) and display the results of the LEFT JOIN.

Leave a Reply