如何从两个不同数据库中的两个表中获取数据 [英] How to get the data from two tables which are in two different databases

查看:88
本文介绍了如何从两个不同数据库中的两个表中获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要一个查询来从两个不同数据库中的两个表中获取数据。

我有像RegId,GaurId,transID这样的列,数据库A中的表A中的payamount,status,paymethod,以及数据库B中表B中的eventid,CAC,Amount,paystatus等颜色。如何联合这些表。任何人都可以帮我这个吗?

解决方案

嘿,如果这两个数据库在同一台服务器上,它只是简单地就像那样



  SELECT  col1,col2,col3  FROM  Database1.Schema1.Table1 
UNION
SELECT col1,col2,col3 FROM Database2。 Schema2.Table2





记住要联合你必须从两者中选择相同数量的列,并且列必须是相同的数据类型。


Hi,
I need a query to get the data from two tables which are in two different databases.
I have the columns like RegId,GaurId,transID,payamount,status,paymethod in table A in database A and having the coloumns like eventid,CAC,Amount,paystatus in table B in Database B.How to union these tables.Can anyone help me regarding this?

解决方案

Hey if the two databases are on the same server its just simply dong like so

SELECT col1, col2, col3 FROM Database1.Schema1.Table1
UNION 
SELECT col1, col2, col3 FROM Database2.Schema2.Table2



And remember to union you must seklect the same numbetr of columns from both and the columns must be the same datatype.


这篇关于如何从两个不同数据库中的两个表中获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆