I have 2 tables in different databases in different mysql hosts. can i write a single SQL statement to implement the inner join operation?
Asked
Active
Viewed 3,458 times
1
-
1possible duplicate of [PHP-Mysql table join from different host](http://stackoverflow.com/questions/3582621/php-mysql-table-join-from-different-host) – Shakti Singh Mar 31 '12 at 06:40
-
Does this answer your question? [Join tables from two different server](https://stackoverflow.com/questions/11114197/join-tables-from-two-different-server) – Nico Haase May 26 '23 at 08:58
4 Answers
1
Depending on your MySQL version, you might be be able to use Federated Storage Engine. Refer to Accessing Distributed Data with the Federated Storage Engine for more information.

BluesRockAddict
- 15,525
- 3
- 37
- 35
0
That would mean connecting to another MySQL host from INSIDE the SQL statement. To my knowledge, this is not possible and I would regard it as highly dangerous if it were.

Mike Adler
- 1,199
- 9
- 24
0
It is not possible to join two tables from different hosts. You can store the result from one of the tables in a hash keyed on the join attribute, and then perform the join operation in your program.

Unos
- 1,293
- 2
- 14
- 35
-4
it is not possible to connect to two databases in same query

Michal
- 3,262
- 4
- 30
- 50

manishbagra
- 58
- 4
-
to two database it is possible: `SELECT db1.tb1.* FROM db1.tb1 LEFT JOIN db2.tb1 ON db1.tb1.field1 = db2.tb1.field1`. The question here was more about hosts than databases – Fabrizio Jul 02 '12 at 20:50
-
Pretty strange that there are a lot of other answers that claim that this **is** possible – Nico Haase May 26 '23 at 08:58