How do you join tables from different databases?

  • plz help me..........

  • Are you still looking out the answer for this.?

    Below is a sample query to join two tables present in two different databases of the same server.

    select a.* from DB1.dbo.[Table] a

    inner join DB2.dbo.[Table] b

    on a.[Col]=b.[Col]

  • Besides using the 3 part name of a table as previous poster indicated (db.owner.table) you could create a view of a table in the current database that selects from the other database. You can then use the view in the joins.

    I've read that you can create a view of a table on another server or instance. Make sure that the user has access to both servers (same password if SS login) and use "exec sp_serveroption 'Server\InstanceName', 'data access', 'true'". You would then use a 4 part name (server.db.owner.table).

    Steve

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply