Reputation: 9131
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
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#
.?
Upvotes: 0
Views: 2231
Reputation: 1
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.
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 ....
Upvotes: 0
Reputation: 970
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.
Upvotes: 1