0

I'm new to SQL, so need a little help. I have to join two tables which are in two different databases which are on different servers. Can someone please tell me how can I do that?

John Gardeniers
  • 27,458
  • 12
  • 55
  • 109

1 Answers1

4

You sure can, as long as you have permission to access the tables on the other server. Just qualify the table names with the server name, database name, and schema name, like so:

SELECT * FROM otherserver.testdb.dbo.MyTable

You'll have to first set up the remote server as a "linked server" - you should be able to find plenty of guides for doing that with a little Google searching, or just pester your local DBA. It's pretty easy when connecting two SQL Server systems, but Kerberos can be a little fussy if you want to impersonate Windows credentials.

db2
  • 2,180
  • 3
  • 15
  • 19
  • 1
    @sharepoint99 If you feel this answer sufficiently resolves your problem, you should accept it as the answer (there should be a checkmark on the left side you can click). – bhamby Mar 29 '11 at 20:01