Jump to content

Joining tables from two different databases


diskhub

Recommended Posts

first you need to have access to both database with the same username and password. assume we have table1 in db1 and table2 in db2

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] t1.* FROM db1.table1 AS t1, db2.table2 AS t2 WHERE t1.id=t2.id [!--sql2--][/div][!--sql3--]

 

As simple as that. You can also use JOIN syntax.

Link to comment
Share on other sites

The inconvenience of having to have similar login credentials to both DBs precludes to use of this technique for any DB that you haven't explicitly set up in this fashion. If it's up to you, keep the related tables in the same DB; if it's not, consider doing this in middleware or via temporary tables, otherwise you'll get caught with your pants down in the credentials ever change!

Link to comment
Share on other sites

[!--quoteo(post=330045:date=Dec 23 2005, 04:54 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Dec 23 2005, 04:54 PM) 330045[/snapback][/div][div class=\'quotemain\'][!--quotec--]

The inconvenience of having to have similar login credentials to both DBs precludes to use of this technique for any DB that you haven't explicitly set up in this fashion. If it's up to you, keep the related tables in the same DB; if it's not, consider doing this in middleware or via temporary tables, otherwise you'll get caught with your pants down in the credentials ever change!

 

I suppose the other important issue is making sure there is a common relational key (ID) between the 2 DB tables.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.