Query 2 tables - each in a different database

Is there any query code that will allow joining tables that are in different databases running on the same server If yes, how is the connection to each handled



Answer this question

Query 2 tables - each in a different database

  • Bad_Bob

    The select code is clear but the connection to the two databases is not when using ADO. Is one connection object used somehow or are the databases linked


  • draxx

    That is no problem.

    SELECT a.Field, b.Field
    FROM dbo.myTable a
    JOIN OtherDatabase.dbo.myTable b ON a.myKey = b.myKey


  • Aquind

    WeslyB is right.

    But your user has to have select rights on the other database.

    You don't have to handle the rights in ADO.

    Regards



  • Query 2 tables - each in a different database