Is it possible to get information from different database with inner join having database in SQL and mySql? - 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 from 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.

Related

Pentaho-spoon Specify mysql connection without database name (for Multiple database access)

I have a scenario where I have two separate databases olap and oltp, in the input-table or scripting(mysql) I want to join tables from these two different databases.
I am not able to leave database column blank when creating a connection, so I can't access both database (and join tables).
One solution suggested in an answer is to put variables in kettle.properties. but I am not sure how can I access those variables inside SQL query( will syntax like this ${} work in SQL?)
Try this:
Choose one database name in the connection.
In the Table input step:
SELECT
table1.field1
, table2.field2
FROM [database1].[schema].table1
INNER JOIN [database2].[schema].table2
If that doesn't work try having two table input ( one for each database ) make sure they are sorted on the column you'll use as a key in the JOIN and use a Merge Join step as shown here:

how can I inner join 2 mysql tables on 2 different mysql server

I am trying to inner join 2 tables located on 2 different MySQL Servers.
I am trying to do something like this:
SELECT id, name FROM server2.db1.account AS new_data
INERT INTO server1.db2.account(id, name)
ON DUPLICATE KEY UPDATE name = new_data.name
In SQL Server there is link server future which allows you to do this but I am not sure how this is done using MySQL Server.
Note: I need to be able to inner join all the tables from one server to another.
I am looking for a solution where I don't have to do every table separately as I have multiple servers and many tables on each database.
Thanks for your time and help.
Go read about the federated engine. It is the MySQL version of linked servers. You will be able to query a remote table like a local table using the federated engine. Read this link.

SQL to ACCESS 2010

I imported my SQL information into Access. How can I create a table in Access, then join or link it to an existing table already in Access 2010.
I just use 'Access Data Projects' (ADP). This allows me to keep everything on the SQL Server side, and it allows me to write stored procedures (and bind them to forms, etc) without writing mountains of linked table / SQL passthrough code.
An easy way is to set up a UNION query. That will leave your two tables intact but join the data.
A JOIN query would merge the data into one of the existing tables.
http://stackoverflow.com/questions/38549/difference-between-inner-and-outer-joins post has some good info about that.

querying databases on same server with linq

In normal sql I could do joins on tables in different databases as long as they were on the same server (or linked servers). In linq I can't figure out how to do that. Is this possible? For example, if I have a database called db1 and another called db2. db1 has a table called people and db2 has a table called address I could do something like...
select a.addressline1, p.firstname
from db1.dbo.people p
inner join db2.dbo.address a on p.peopleid = a.peopleid
Is this possible with linq? Thanks.
Multiple databases under a single context is not directly supported. Create views in the first database that point at tables in the second, and map entities to those views.
This article also shows this, and an alternative option by manually editing the datasource property:
http://damieng.com/blog/2010/01/11/linq-to-sql-tips-and-tricks-3
Personally when i need joins in LINQ-to-SQL i just make them in SQL. With LINQ they're rather difficult to write but it should be possible with the .JOIN selector in LINQ.
Another way to writing LINQ-queries is explained here
try using db1.ExecuteQuery(#"your query")
HTH

How access data between databases in mysql?

I'm working in a project that is divided into multiple modules. Each module have it's own independent database in mysql, but now, the modules need to obtain data between them. For example we're going to develop a new "admin" module, and every other modules need to access the data in the "admin" database. I know that I can make a query like
select * from admin.table
to obtain data from other database, but each module (and the new "admin" module) are created in CakePHP. I think one possible solution is use something like Synonyms (like the ones in Oracle or SQL Server), but MySQL don't support it. Someone have a better idea? Thanks
I have a feeling CakePHP can handle cross-database relations. Try setting $useDbConfig for each model to a connection for the respective database. CakePHP should generate multiple queries (atleast one per database connection) and join the results together for you. This approach should work fine for simple relations, but there might not be full support for relations such as HABTM.
How about using views:
create view admin_table as select * from admin.table
Then, you just need to set $tableName to admin_table.
I may be wrong, but I think querying is based on
select * from database.owner.table ... and the implied owner would be the "dbo" (database owner). So, you MIGHT be able to do the following...
select a1., b1. from database1.table1 a1, database2.table2 b1 where a1.fld1 = b1.fld1 ...