Solved

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

Posted on 2007-11-21
5
3,551 Views
Last Modified: 2012-08-14
I need to run a query that joins two tables from two different databases.
0
Comment
Question by:edenmachine
5 Comments
 
LVL 21

Expert Comment

by:mastoo
ID: 20328484
Select * From DatabaseOneName..TableOneName Join DatabaseTwoName..TableTwoName On some join conditions here
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20328492
prefix "databaseName.." while specifying the table



from db1.dbo.Table1 a
inner join db2.dbo.Table2 b on a.id = b.id
0
 
LVL 6

Accepted Solution

by:
messen1975 earned 125 total points
ID: 20328592
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
 
LVL 1

Author Closing Comment

by:edenmachine
ID: 31410384
Yes, they were in different servers so this is what I needed.
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 20329306
So what was the pbm with the above two comments
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question