This can be achieved with adding database name in front of a table name in MySql query.
For example:
SELECT * FROM database_name1.table1_name tb1 INNER JOIN database_name2.table2_name tb2 ON tb1.field_name=tb2.field_name

Just please make sure that MySql user that your site is connecting with has the right privileges for every database in MySql query.