Inner Join two tables from two database connections in query

I need to inner join two different tables from different database connections. How would I do this in a query from say “database1”?

SELECT
*
FROM
table1 t1
INNER JOIN
dbConn2.database2.table2 t2 ON t1.Field = t2.Field

You cannot join using database connections.

If database2 is on the same server as database1, you can do this.

SELECT * FROM table1 t1 INNER JOIN database2.table2 t2 ON t1.Field = t2.Field

They are on different servers but I got it figured out, thanks!

SELECT
*
FROM
table1 t1
INNER JOIN
[SeverName].Database2.dbo.Table2 t2 ON t1.Field = t2.Field

1 Like

What is the proper syntax for referencing the server name?

1 Like