hi,
Sir i want to access records from two tables one from a database and other from different database ?
Access table from other database
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Sam HobbsRank #107 · 20.5K reputationPosted Apr 17, 2012, 9:36 AM EDT
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 17, 2012, 7:33 PM EDT
Hi,
If we have these two database on same Database server then directly use these tables.
Example:
I have two database like db1 and db2 and have tables table1 and table2 respectively.
Select col1 as COL1 from db1..table1
union
Select col2 as COL1 from db2..table2
OR
Select col1 as COL1 from db1..table1 t1
INNer JOIN db2..table2 t2 ON t1.col1 = t2.col2
If these two db are on differnt server then use linked server.
hope this help.
SenthilkumarRank #387 · 6.5K reputationPosted Apr 17, 2012, 7:35 PM EDT
Yes, you can do it easily if both databases comes under the same sql server machine.
For example,
I have two database called Products and another database called Sales
My application connected with the ProductsMaster database
you need to create the object for the table with the correct database.
It will give the joined results.
Hope this will help you.