Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.