连接两个不同数据库中的表?

时间:2021-05-12 09:55:05

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

在MySQL中,我有两个不同的数据库——我们称它们为A和B。

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

是否可以在数据库a中的表和数据库B中的表之间执行联接?

3 个解决方案

#1


112  

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.

您只需要在表引用前面加上它所驻留的数据库的名称。

#2


5  

SELECT <...> 
FROM A.tableA JOIN B.tableB 

#3


1  

SELECT *
FROM A.tableA JOIN B.tableB 

or

SELECT *
  FROM A.tableA JOIN B.tableB
  ON A.tableA.id = B.tableB.a_id;

#1


112  

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.

您只需要在表引用前面加上它所驻留的数据库的名称。

#2


5  

SELECT <...> 
FROM A.tableA JOIN B.tableB 

#3


1  

SELECT *
FROM A.tableA JOIN B.tableB 

or

SELECT *
  FROM A.tableA JOIN B.tableB
  ON A.tableA.id = B.tableB.a_id;