Home >Database >Mysql Tutorial >Can I perform cross-database queries and inserts in a single SQL statement?
Cross-Database Queries and Inserts
Can you perform data retrieval (SELECT) or manipulation (INSERT) operations across multiple databases housed on the same server?
Yes, you can! To do so, utilize the following syntax:
databasename.tablename
For instance, let's say we have two databases, "mydatabase1" and "mydatabase2," each with a table named "tblUsers." To retrieve data from both tables, we would 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 I perform cross-database queries and inserts in a single SQL statement?. For more information, please follow other related articles on the PHP Chinese website!