MySQL 跨不同数据库选择列
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/674115/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Select columns across different databases
提问by Graviton
Is it possible to do a select ( or insert) statement across different databases that are located on the same server? If yes, how?
是否可以跨位于同一服务器上的不同数据库执行选择(或插入)语句?如果是,如何?
回答by TheTXI
You would specify the database by using the syntax databasename.tablename
您将使用语法指定数据库 databasename.tablename
Example:
例子:
SELECT
mydatabase1.tblUsers.UserID,
mydatabse2.tblUsers.UserID
FROM
mydatabase1.tblUsers
INNER JOIN mydatabase2.tblUsers
ON mydatabase1.tblUsers.UserID = mydatabase2.tblUsers.UserID
回答by ólafur Waage
You can select from any other table with a JOIN statementand using this type of syntax.
您可以使用JOIN 语句并使用这种类型的语法从任何其他表中进行选择。
SELECT A.*, B.* FROM db1.table1 A LEFT JOIN db2.table1 B ON A.id = B.id