[英]Execute a Query with join in two tables from different database of same MySQL Server
I need to execute a Query(Select only) with join of two tables from different database of same server. 我需要使用来自同一服务器的不同数据库的两个表的联接来执行查询(仅选择)。
Eg query will be similar to: 例如查询将类似于:
SELECT * FROM DB1.tbl_a LEFT JOIN DB2.tbl_b ON DB1.tbl_a.fieldX = DB2.tbl_b.fieldY WHERE ....
Where tbl_a
, tbl_b
are 2 tables from 2 different database DB1
, DB2
respectively 其中
tbl_a
和tbl_b
是分别来自2个不同数据库DB1
和DB2
2个表
How to do that? 怎么做? How can I connect to MySQL server without specifying the database in the connection string but in sql query Using
C#
.? 如何在不使用连接字符串但在使用
C#
sql查询中指定数据库的情况下连接到MySQL服务器?
Actually this question has already been answered, here is the answer : 其实这个问题已经回答了,这是答案:
Yes, assuming the account has appropriate permissions you can use: 是的,假设该帐户具有适当的权限,则可以使用:
SELECT ...
FROM A.table t1
JOIN B.table2 t2 ON t2.column = t1.col
You just need to prefix the table reference with the name of the database it resides in. 您只需要在表引用前面加上它所驻留的数据库的名称即可。
I need to execute a Query(Select only) with join of two tables from different database of same server.
我需要使用来自同一服务器的不同数据库的两个表的联接来执行查询(仅选择)。
For this SQL User have access on both Databases. 对于此SQL用户,可以访问两个数据库。
Query will be like this: 查询将是这样的:
SELECT * FROM [DB1].[dbo].[tbl_a] T1 LEFT JOIN [DB2].[dbo].[tbl_b] T2 ON T1.fieldX = T2.fieldY WHERE .... 选择* FROM [DB1]。[dbo]。[tbl_a] T1左联接[DB2]。[dbo]。[tbl_b] T2 ON T1.fieldX = T2.fieldY WHERE ....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.