Home >Database >Mysql Tutorial >Can MySQL Join Tables Across Different Databases?
Performing Inter-Database Joins in MySQL
In MySQL, you may encounter scenarios where you need to join tables from different databases. This article will delve into the possibility of performing such joins, providing the necessary syntax and guidelines.
Question: Is it possible to join tables from two different databases in MySQL?
Answer: Yes, it is possible to perform inter-database joins in MySQL.
Syntax:
SELECT <column_list> FROM <db_name1>.<table_name1> <alias1> JOIN <db_name2>.<table_name2> <alias2> ON <alias1>.<column_name> = <alias2>.<column_name>
Explanation:
Example:
Consider two databases, A and B, with tables table1 and table2, respectively. To join these tables, you can use the following query:
SELECT * FROM A.table1 t1 JOIN B.table2 t2 ON t2.column2 = t1.column1;
Note:
The above is the detailed content of Can MySQL Join Tables Across Different Databases?. For more information, please follow other related articles on the PHP Chinese website!