Selecting Columns Across Multiple Databases
Is it possible to perform SQL SELECT (or INSERT) statements across multiple databases residing on the same server? If so, how?
Solution:
Yes, it is possible to access columns from different databases in a single query. To do so, specify the database name followed by the period (.) character and then the table name.
Database Name Syntax:
databasename.tablename
Example Query:
SELECT mydatabase1.tblUsers.UserID, mydatabse2.tblUsers.UserID FROM mydatabase1.tblUsers INNER JOIN mydatabase2.tblUsers ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID
In this example, the query retrieves the UserID columns from two tables, tblUsers, located in the mydatabase1 and mydatabse2 databases.
The above is the detailed content of Can I perform SQL SELECT statements across multiple databases on the same server?. For more information, please follow other related articles on the PHP Chinese website!