开发者

Is it possible to get information from different database with inner join having database in SQL and mySql?

I have my project A with mySql database and I have another project B with msSql. I have connected the database from A and fetched data 开发者_如何学Cfrom B. But now I need to use inner join for tables in A and B. Is it possible to do so with databases in the same server and different server? Any help will be appreciated.

Thanks in advance


Yes, it should be possible. First, you will need to link your MySQL server to your MS SQL Server.
See this reference. Secondly, you will probably need to use sub queries to select the correct columns and do the join on them;

SELECT *
FROM
  (SELECT ms_column1, ms_column2 FROM MSSQLTABLE) AS mssql
JOIN
  (SELECT my_column1, my_column2 
   FROM openquery(LINKED_SERVER, 'SELECT column1, column2 FROM MYSQLTABLE') AS mysql
  ON mssql.ms_column1 = mysql.my_column1

Unfortunately untested.


Instead of making the two different databases communicate between themselves you can move the logic of the communication to the programming layer. For example using PDO and PHP you can connect to both databases, get the data, mix it and produce a result. You can create an abstraction layer of PHP classes that get information independently from A or B databases, and later you will not care anymore about it, as you will work with PHP objects not directly with databases.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜