从不同的数据库中选择两个或多个表 [英] Select two or multiple tables from different databases
本文介绍了从不同的数据库中选择两个或多个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单个查询中使用两个表,这两个表位于不同的数据库中,意味着,
how to use two tables in a single query, which are in different databases, means,
SELECT table1.id, table1.name, table2.id, table2.telephone
FROM table1, table2
WHERE table1.id = table2.id
在这里,table1
和table2
在单独的数据库中.
here, table1
and table2
are in separate database.
推荐答案
您可以进行跨数据库联接,没问题.只需在表名前面加上数据库名即可.
You can do cross-database joins, no problem. Simply prefix your table name with database name.
SELECT t1.id, t1.name, t2.id, t2.telephone
FROM db1.table1 t1
INNER JOIN db2.table2 t2 on t1.id = t2.id;
但是请注意权限.如果用户无权访问其中一个数据库,则此选择将失败.
Be wary of permissions, though. If a user doesn't have access to one of the databases, this select will fail.
这篇关于从不同的数据库中选择两个或多个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文