I am writing a script in Python and I am using MySQLdb
package.
con1 = mdb.connect('127.0.0.1', 'root', '', 'teacher')
con2 = mdb.connect('127.0.0.1', 'root', '', 'student', true)
I can execute a query using a single cursor in python. But I want to write query to use tables from both the database at once. How can I do that?
Was looking for an answer to the same question. Found that connecting without specifying the database will allow you to query multiple tables:
db = _mysql.connect('localhost', 'user', 'password')
Then you can query different tables from different databases:
select table1.field1,
table2.field2
from database1.table1 inner join
database2.table2 on database2.table2.join_field = database1.field1.join_field
And boom goes the dynamite
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With