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.
LVL 1
edenmachineAsked:
Who is Participating?
 
messen1975Connect With a Mentor Commented:
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.