Linking query between 2 databases

  • We have 2 databases on 1 SQL server.  Is there a way to link the tables between these two databases in 1 select statement?  If so, what is the syntax. 

     

    Thanks ahead for any help.

  • Do you mean to select from both, or run a join?

    SELECT A.COL1, B.COL2 FROM DB1.DBO.TABLEA A, DB2.DBO.TABLEB B

    SELECT A.COL1, B.COL2 FROM DB1.DBO.TABLEA A INNER JOIN DB2.DBO.TABLEB B ON A.COL1 = B.COL1



    Shamless self promotion - read my blog http://sirsql.net

  • Thanks for your reply, we figured it out.

    Database A (main database)

    Database B (secondary database)

     

    We were leaving out the dbo name from database B when we initially were trying to do the query.

     

    It works if we:

    select a.table, b.dbo.table

    from a, b

    where a.column = b.column

  • That darn table owner will get you every time!  Makes you wonder if it's outlived it's usefulness and should be eliminated in a future SQL server version?

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

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