diskhub Posted December 21, 2005 Share Posted December 21, 2005 How do you cross databases joining? Quote Link to comment https://forums.phpfreaks.com/topic/3083-joining-tables-from-two-different-databases/ Share on other sites More sharing options...
ryanlwh Posted December 21, 2005 Share Posted December 21, 2005 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. Quote Link to comment https://forums.phpfreaks.com/topic/3083-joining-tables-from-two-different-databases/#findComment-10299 Share on other sites More sharing options...
fenway Posted December 23, 2005 Share Posted December 23, 2005 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! Quote Link to comment https://forums.phpfreaks.com/topic/3083-joining-tables-from-two-different-databases/#findComment-10338 Share on other sites More sharing options...
dbrimlow Posted December 30, 2005 Share Posted December 30, 2005 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/3083-joining-tables-from-two-different-databases/#findComment-10487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.