Join two tables on different databases

2019-08-10 22:07发布

问题:

I have following databases:

  1. test

    table1
      fields: id, password, name, lastname
    
  2. test2

    table2
      fields: id
    

How to select test and test2 where table1 have id in test2.table2.id?

回答1:

Have you tried it? You just write the database name test2.dbo.tblFoo, though you may need to declare an alias (just write a word after writing the actual name). And the account will obviously need permissions to both DBs.



回答2:

SELECT /* stuff */
FROM table1 t1
JOIN table2 t2 ON t1.id = t2.id


回答3:

I can use some functionality in ORM, Hibernate Shards for example.