Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Query multiple SQL databases in a single query

I would like to join data in multiple tables from the same server, something like:

 

SELECT *

FROM server-x.db1.tblA

INNER JOIN server-x.db2.tblB

ON server.db2.tblB.someColumn = server.db1.tblA.SomeColumn

WHERE server.db1.tblA.something = 'whatever'

 

Hasn't worked so far for me in the several variations that I've tried...is it possible and if so, what am I missing? I know I can bring the data into multiple tables in Power BI and then do a merge on them, but I would prefer to use a single query up front. Thanks!

Status: New
Comments
jim_boyce
New Member

 

Yes, I know there is an error in that WHERE clause... 🙂

Bobfather
Frequent Visitor
For me, it works to write my query as you listed. I Get Data from DB2 Database, enter the Server & DB name, and then a query like the following: SELECT A.COLUMN ,B.DATA FROM DATABASE1.SCHEMA.TABLE A LEFT JOIN DATABASE2.SCHEMA.OTHER_TABLE B ON A.KEY = B.KEY Maybe it works for me because I use the same access (username & password) for both databases?