paul bennett

Joins across different database tables

Posted on: March 18, 2008

Join tutorials always tell you how to join tables in the same database, but what if you need to join tables which sit in different databases?

Turns out this is nice and simple[1] (in MySQL, your db engine may vary):

SELECT this-db.table-one.column-one, other-db.table-two.column-two
FROM this-db.table-one
LEFT JOIN other-db.table-two
ON =

Simply put, the ‘dot operator’ lets you specify database as a parent of table in the same way you normally specify table as a parent to a column.

[1] assuming the account you use to connect to the database has rights across both databases. If not you’ll need to set up an account which does.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: