Join between tables in two different databases?

user3262424 picture user3262424 · Apr 18, 2011 · Viewed 133.4k times · Source

In MySQL, I have two different databases -- let's call them A and B.

Is it possible to perform a join between a table that is in database A, to a table that is in database B?

Answer

OMG Ponies picture OMG Ponies · Apr 18, 2011

Yes, assuming the account has appropriate permissions you can use:

SELECT <...>
FROM A.table1 t1 JOIN B.table2 t2 ON t2.column2 = t1.column1;

You just need to prefix the table reference with the name of the database it resides in.