Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Query from tables in different databases

Author  Topic 

Daniel Israel
Starting Member

15 Posts

Posted - 2006-11-16 : 13:17:53

I have 2 different databases on my server. I've logged in and I have access to both. Is there a way to access tables from both databases in a single query?

In Database A, I have table X
In Database B, I have table Y

I'd like to do a select by joining tables X and Y.

Is this possible?

Thanks.

-D. Israel

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-11-16 : 13:30:25
Reference the table using 3 part names:

DatabaseName.Owner.ObjectName


select YourColumn
from DatabaseA.dbo.TableX x
inner join DatabaseB.dbo.TableY y
on x.YourColumn = y.YourColumn



Nathan Skerl
Go to Top of Page

Daniel Israel
Starting Member

15 Posts

Posted - 2006-11-16 : 15:54:36

Forgot the owner! DOH!

Does this work on 2000, or just on 2005?

Thanks.

-D. Israel
Go to Top of Page

nathans
Aged Yak Warrior

938 Posts

Posted - 2006-11-16 : 16:02:25
Should be fine in both.

Nathan Skerl
Go to Top of Page
   

- Advertisement -