我有一个程序从数据库输出结果,但数据源来自五个数据库。是否可以输出来自五个数据库的数据?谢谢。
答案 0 :(得分:0)
用于从多个数据库获取数据的样本选择查询
SELECT * FROM DB1.dbo.MyTable
UNION ALL
SELECT * FROM DB2.dbo.MyTable
答案 1 :(得分:0)
**
select DD.DISTRICT_NAME, MM.MANDAL_NAME,GP_NAME from
(
select District_id,substring(sn_vo_id,3,4) as mandal,Gp_id,sn_vo_id,MEMBER_ID,sn_member_name,sn_amount_paid_date,Project_Type_ID,Activity,status
from pop_nov18..tbl_scsp_hlp_new where hh_id is null and MEMBER_ID not in
(select MEMBER_ID from pop_nov18..IB_SHG_MEMBER_DETAILS)
) a left join UnnathiMasters.[dbo].[vo_master] vo on a.sn_vo_id=vo.VO_id
left join UnnathiMasters.[dbo].[gp_master] GP on a.Gp_id=GP.GP_ID
left join UnnathiMasters.[dbo].[mandal_master] MM on a.mandal=mm.MANDAL_ID
left join UnnathiMasters.[dbo].[district_master] DD on a.District_id=DD.DISTRICT_ID
left join SC_ST_Bluefrog_2013..SCSP_HLP_MASTER AC on a.Activity=AC.sub_activity_code
**
在上面的查询中,POP_nov18,UnnathiMasters和SC_ST_Bluefrog_2013是三个不同的数据库。