• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3559
  • Last Modified:

How can you connect two tables together from two different databases?

I need to run a query that joins two tables from two different databases.
0
edenmachine
Asked:
edenmachine
1 Solution
 
mastooCommented:
Select * From DatabaseOneName..TableOneName Join DatabaseTwoName..TableTwoName On some join conditions here
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
prefix "databaseName.." while specifying the table



from db1.dbo.Table1 a
inner join db2.dbo.Table2 b on a.id = b.id
0
 
messen1975Commented:
Are the two databases on the same server?  If they are are you can just specify the database name as they said above.

If they aren't you have to create a linked server:
http://msdn2.microsoft.com/en-us/library/ms188279.aspx

0
 
edenmachineAuthor Commented:
Yes, they were in different servers so this is what I needed.
0
 
Aneesh RetnakaranDatabase AdministratorCommented:
So what was the pbm with the above two comments
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now