I have a program that output results from database but the source of data comes from five databases. Is it possible to output the data coming from five databases? Thank you.
Asked
Active
Viewed 57 times
-2
-
It's not possible to get data from multiple databases using single query – Anil Jul 13 '17 at 05:13
-
Even if I use the commands like "JOIN", "UNION" and other commands like that? @Anil – Lanz Joshua Jul 13 '17 at 05:15
-
Do you mean databases or tables? – Tim Biegeleisen Jul 13 '17 at 05:15
-
Does all those schemas in the same database or different database ? – Anil Jul 13 '17 at 05:16
-
It's database. I'm using MySQL and PHP for my program. All databases are stored in my local server. – Lanz Joshua Jul 13 '17 at 05:22
-
Possible duplicate of [Select columns across different databases](https://stackoverflow.com/questions/674115/select-columns-across-different-databases) – John3136 Jul 13 '17 at 05:27
-
Yes it is possible if all database are on single MSSQL server – Rohit Poudel Jul 13 '17 at 05:34
2 Answers
0
sample select query for getting data from multiple database
SELECT * FROM DB1.dbo.MyTable
UNION ALL
SELECT * FROM DB2.dbo.MyTable

sekaraja
- 177
- 1
- 1
- 8
0
yes its possible. Try like below query:
**
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
**
In above query,POP_nov18,UnnathiMasters and SC_ST_Bluefrog_2013 are three different databases.

Rajesh G
- 44
- 4