62

Is it possible to do a select ( or insert) statement across different databases that are located on the same server? If yes, how?

2 Answers 2

88

You would specify the database by using the syntax databasename.tablename

Example:

SELECT 
    mydatabase1.tblUsers.UserID, 
    mydatabse2.tblUsers.UserID
FROM 
   mydatabase1.tblUsers
       INNER JOIN mydatabase2.tblUsers 
           ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID
Sign up to request clarification or add additional context in comments.

Comments

10

You can select from any other table with a JOIN statement and using this type of syntax.

SELECT A.*, B.* FROM db1.table1 A LEFT JOIN db2.table1 B ON A.id = B.id

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.