chad.portman Posted September 23, 2014 Share Posted September 23, 2014 I am very new to SQL and I have noticed that I can have multiple database connections at the same time. But when you open a new query it is for just one database. Can we write a query that access multiple databases and how do we handle that when they have the same table names? Link to comment Share on other sites More sharing options...
niche Posted September 23, 2014 Share Posted September 23, 2014 (edited) Once a connection is open it stays open until it's closed or the script finishes.This will also help:http://stackoverflow.com/questions/3686014/how-to-select-fields-from-different-dbs-with-the-same-table-and-field-name Edited September 23, 2014 by niche Link to comment Share on other sites More sharing options...
chad.portman Posted September 23, 2014 Author Share Posted September 23, 2014 (edited) Thank you the link helped a lot. But I guess I should be more clear I was saying Databases earlier. I meant to say I have Multiple Database Engines connect that have the same names of their respective Databases, Tables, and column names. And was wondering if you could link between the database engines. Edited September 23, 2014 by chad.portman Link to comment Share on other sites More sharing options...
niche Posted September 23, 2014 Share Posted September 23, 2014 On different servers? Link to comment Share on other sites More sharing options...
chad.portman Posted September 23, 2014 Author Share Posted September 23, 2014 yes Link to comment Share on other sites More sharing options...
Ingolme Posted September 23, 2014 Share Posted September 23, 2014 If you're dealing with different servers you will have to pull the information from the databases independently from each other. MySQL only works inside its own server. If you're dealing with multiple databases on the same server you can get content from the tables by prepending the database's name to the table name. Example: SELECT t1.field1, t1.field2, t2.field1 FROM database1.table1 AS t1, database2.table1 AS t2 WHERE t1.id = t2.id Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now