Solved

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

Posted on 2007-11-21
5
3,555 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

730 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