user3262424
user3262424

Reputation: 7479

MySQL -- transaction involving tables in 3 different databases?

In MySQL, I have three different databases -- let's call them A, B and C.

Is it possible to perform a transaction involving tables that are in all three databases (A, B, C)? (all databases are on the same server)

Upvotes: 0

Views: 442

Answers (1)

Harry Joy
Harry Joy

Reputation: 59660

Yes you can. This is a demo query:

select (SELECT count(*) FROM `A`.`tableInA`),
       (SELECT count(*) FROM `B`.`tableInB`),
       (SELECT count(*) FROM `C`.`tableInC`);

Another demo query:

SELECT * FROM `A`.`tableInA` 
      where fieldInA in (SELECT fieldInAB FROM `B`.`tableInB` 
            where fieldInB in (select fieldInBC from `C`.`tableInC`));

Upvotes: 3

Related Questions