MySQL: Join Tables from Different Databases

September 08, 2006, 05:21 pm

Holy shit, this just made my life a million times easier!

If you should need to access tables from multiple databases, or even JOIN tables from multiple databases, you can (provided the user you're connecting with has sufficient privileges):

SELECT
    c.customer_name,
    o.order_date
FROM
    db1.tbl_customers c LEFT JOIN
    db2.tbl_orders o ON o.customer_id = c.id