Home >Database >Mysql Tutorial >Can SQL Queries Access Data from Multiple Databases on the Same Server?
Querying Data from Multiple Databases
Can SQL queries span multiple databases residing on the same server? Let's explore this possibility.
Answer:
Yes, it is possible to execute SELECT (or INSERT) statements across different databases within the same server. This is achieved by explicitly specifying the database name in the query syntax:
databasename.tablename
Example:
To select the UserID column from the tblUsers table in both mydatabase1 and mydatabase2, use the following query:
SELECT mydatabase1.tblUsers.UserID, mydatabse2.tblUsers.UserID FROM mydatabase1.tblUsers INNER JOIN mydatabase2.tblUsers ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID
The above is the detailed content of Can SQL Queries Access Data from Multiple Databases on the Same Server?. For more information, please follow other related articles on the PHP Chinese website!