Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bugcy013/939134ac5c8a2e5e3bb36ad19ac34599 to your computer and use it in GitHub Desktop.
Save bugcy013/939134ac5c8a2e5e3bb36ad19ac34599 to your computer and use it in GitHub Desktop.
Python MySQLdb- using multiple database tables in query

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment