Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you join tables from two different SQL Server instances in one SQL query [duplicate]

Tags:

Possible Duplicate:
Selecting data from two different servers in SQL Server

How can I join two tables, which are located two different SQL Server instances, in one query?

like image 464
Tarik Avatar asked Sep 14 '09 21:09

Tarik


People also ask

How do you avoid duplicates when joining tables?

Solution. Select column values in a specific order within rows to make rows with duplicate sets of values identical. Then you can use SELECT DISTINCT to remove duplicates. Alternatively, retrieve rows in such a way that near-duplicates are not even selected.

How do I join two tables in SQL without duplicates?

The SQL UNION ALL operator is used to combine the result sets of 2 or more SELECT statements. It does not remove duplicate rows between the various SELECT statements (all rows are returned). Each SELECT statement within the UNION ALL must have the same number of fields in the result sets with similar data types.

How do you find duplicates in SQL using joins?

Check for Duplicates in Multiple Tables With INNER JOINUse the INNER JOIN function to find duplicates that exist in multiple tables. Sample syntax for an INNER JOIN function looks like this: SELECT column_name FROM table1 INNER JOIN table2 ON table1. column_name = table2.


1 Answers

The best way I can think of to accomplish this is via sp_addlinkedserver. You need to make sure that whatever account you use to add the link (via sp_addlinkedsrvlogin) has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:

SELECT * FROM server1table     INNER JOIN server2.database.dbo.server2table ON ..... 
like image 97
Scott Anderson Avatar answered Oct 10 '22 02:10

Scott Anderson