Friday, September 14, 2012

Joining MySQL tables from different schemas

Today I ran into a situation whereby a client needed to join 2 tables which happened to be in different schemas but on the same host. One of the schemas was not being replicated and this particular table was moved appropriately there. To join tables which reside in different schemas, it is very simple:

SELECT u1.*, u2.* FROM database1.users u1 LEFT JOIN database2.users u2 ON u1.id=u2.id WHERE u2.id > 10 and u1.id < 100
Post a Comment