locked
select from two datatables RRS feed

  • Question

  • User-1962684534 posted

    hi, i have two datatables from two different databases..

    dt1: id,name

    dt2: id,address

    i ll take name and address from two datatables where 'id' is common

    now i want a datatable with three columns.. id,name,address

    searched different sources, but very confusing..pls let me know how can i do this??.. can i just query like sql??.. or is there anyother way to do?.. pls let me know..

    Thanks

    Sunday, March 6, 2011 9:49 PM

Answers

  • User77042963 posted

    Try this syntax to retrieve data from tables from different database. If your table schema is other than dbo, you may need to make adjustment to fit your situation:

    SELECT a.id, a.name, b.address FROM db1.dbo.dt1 a INNER JOIN db2.dbo.dt2 b ON a.id=b.id
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 6, 2011 10:02 PM

All replies

  • User77042963 posted

    Try this syntax to retrieve data from tables from different database. If your table schema is other than dbo, you may need to make adjustment to fit your situation:

    SELECT a.id, a.name, b.address FROM db1.dbo.dt1 a INNER JOIN db2.dbo.dt2 b ON a.id=b.id
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, March 6, 2011 10:02 PM
  • User-1962684534 posted

    Hii, 

    tnx a lot for d reply..

    I am using mysql database. I have two connection strings for two databases.So, which connection should i use now to get this query executed

    Thanks

    Sunday, March 6, 2011 10:31 PM