Linking Two Databases in a SQL Query

Linking Two Databases in a SQL Query

I have two databases, each on a separate machine in a network. I want to generate a report extracting data from table1 in database1 and table2 in database2.

How do I link the two databases in my SQL query?

First you have to identify the servers to each other as linked servers. Then you have to create logins for each server onto its linked server. They will recognize each other. Use fully qualified names to retrieve the respective tables.


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist