5ba8cabe450348c7fbe2
5ba8cabe450348c7fbe2

Reputation: 165

MySQL MERGE table across separate databases

I have a database db1 which contains tables tbl1, tbl2, and tbl3.

I also have an empty database db2.

Can I create a MERGE table mrg1 which merges the contents of tbl1, tbl2, and tbl3 from database db1, but is stored in database db2?

Upvotes: 0

Views: 536

Answers (1)

invertedSpear
invertedSpear

Reputation: 11054

Yes, if your database is set up to allow you to run queries against multiple databases at once. I think it would look something like this,

INSERT INTO db2.mrg1 (colA,colB,ColC)
(
  SELECT colA,colB,ColC
  FROM db1.tbl1,db1.tbl2,db1.tbl3
  WHERE [whatever joins your tables together]
)

Upvotes: 1

Related Questions