Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

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

Posted on 2007-11-21
5
Medium Priority
?
3,558 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 375 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
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
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

647 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