Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing Tables in other Databases 1

Status
Not open for further replies.

dt2demar

Technical User
Nov 20, 2000
32
CA

I use the query analyzer to execute my queries. I use the drop down menu on the top right of the screen to select the database I am applying the query to.

How can I run the query on a particular database, and yet include fields from tables in another database in my query?

eg.

Select Distinct
TableA.Field1
TableA.Field2
TableB.Field1

etc.

where the query is being executed in the database in which TableA resides and TableB is in another database.

Thanks for any help on this (probably pretty basic) question.
 
First of all, you should have at least read access rights to both database you are trying to execute the query from. Next you can change your select statements as :

Select Distinct
A.Field1,
A.Field2,
B.Field1,
B.Field2
from
database1..TableA A,
database2..TableB B
where
A.Field1 = B.Field1

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top