Make INNER JOIN on two different bases

Asked

Viewed 130 times

1

I have 2 different Mysql databases, I can make a query on one basis or another specifying which connection I will use so:

$result1 = mysql_query($sql1, $banco1);
$result2 = mysql_query($sql2, $banco2);

Now a problem has arisen, I need in the same query to do an INNER JOIN with different bank tables, is it possible? (something like this)

$sql0 = "SELECT * FROM tabela1_banco1
INNER JOIN id ON tabela2_banco2.id = tabela1_banco1.id_usuario";
$result0 = mysql_query($sql0, $banco1, $banco2);
  • Gives error, or shows no value?

  • Error, it does not collect 2 banks: mysql_query() expects at Most 2 Parameters, 3 Given

  • @caiocafardo, the answer below solved the problem?

1 answer

0

Yes, it is possible; you just need to reference the banks to which the tables belong:

$sql0 = "SELECT * 
   FROM banco1.tabela
   INNER JOIN banco2.tabela ON banco2.tabela.id = banco1.tabela.id";
  • I didn’t keep it working, like $result2 = mysql_query($sql2, $banco2);?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.