开发者

Is it possible to implement JOIN queries with 2 Mysql Databases?

I am working in Moodle and CodeIgnitor together in one project; a few of my tables are in moodle db and other tab开发者_如何学JAVAles are in another database.

Is it possible to implement JOIN queries with two Mysql Databases to fetch the data we require?


YES

  • both database are using the same daemon (meaning same port, same server)
  • user account has enough ACL to access both databases
  • if you are able to construct query yourself

NO

  • certain framework / data modelling will restrict you do so (that's mean the CODE teaching you how to do the SQL, and you cannot against their rules (unless putting your hack)


Yes.

If DB are on the same server, you can use

select a.col from db1.table1 a, db2.table2 b where a.col = b.col 

Obviously you would put your join condition in here.


Yes.

Instead of using the "default" (currently selected) database, you can explicitly specify the database name when you reference your tables and fields:

You can refer to a table within the default database as tbl_name, or as db_name.tbl_name to specify a database explicitly. You can refer to a column as col_name, tbl_name.col_name, or db_name.tbl_name.col_name

However, I don't recommend this. If data are related between tables then they are supposed to be in the same database. That's what would make sense!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜