join tables from multiple mysql host - mysql

I have 2 tables in different databases in different mysql hosts. can i write a single SQL statement to implement the inner join operation?

You can try to use federated table. Read this and this for limitation on using it.

Depending on your MySQL version, you might be be able to use Federated Storage Engine. Refer to Accessing Distributed Data with the Federated Storage Engine for more information.

That would mean connecting to another MySQL host from INSIDE the SQL statement. To my knowledge, this is not possible and I would regard it as highly dangerous if it were.

It is not possible to join two tables from different hosts. You can store the result from one of the tables in a hash keyed on the join attribute, and then perform the join operation in your program.

it is not possible to connect to two databases in same query

Related

Joining tables across multiple servers

I guess we can do database1.table1 join database2.table2 on etc. I.e. join tables in separate databases on the same server.
Is it possible to join tables across different sql servers?
you can use FEDERATED Storage Engine.
The FEDERATED storage engine lets you access data from a remote
MySQL database without using replication or cluster technology.
Querying a local FEDERATED table automatically pulls the data
from the remote (federated) tables. No data is stored on the local tables.
The site shows a good illustration

Is it possible to create a transactional merge table in mysql?

MySQL docs say that tables that use the MERGE storage engine can only union underlying MyISAM tables, which don't allow use of transactions.
Is there an alternative or workaround so that I can have a table that contains the data of several transactional tables in MySQL?
Also, MySQL 4... I know, I know, but it's what I'm stuck with.
Perhaps you could use a view to accomplish this. I'm not too sure if you need the full insert, update, delete functionality or if you just want to select from many tables.

select from another mysql host

is it possible to execute a SELECT command on a mysql host db2, being logined to mysql host db1?
e.g. i'm logined on mysql server db1, and i want to SELECT some data from db1 tables and db2 server tables with one query. i've found out that i can use FEDERATED tables, but i'm looking for a simpler way, if it exists
I do not think there is a simpler way. I can't find one, at least.
I did a bit or research on this. (Was interested.) The manual entry for the SELECT query mentions nothing that would allow it to connect to a database on a second server, and I can't see anything else that would allow it either. (Nothing in the JOINS, nothing in the CREATE TABLE syntax, just nothing...)
Except for the FEDERATED engine, that is. This is exactly why it was crated; to allow this sort of thing.
I suppose you could try to set your OS up to create a symbolic link to the data files of a second server and have the first server set up a table that targets that, but that's hardly an improvement over the FEDERATED engine.
In any case, if there are other alternatives, I doubt they are simpler than the FEDERATED engine. I would at least give it a try.

Can I join between two MySQL tables stores on separate machines?

I have a relatively light query that needs information from a local MySQL table along with another MySQL table which is stored on a physically separate machine (on the same network). I'm keen to avoid setting up replication just to facilitate this light query that only needs executed once a day.
Is there any way that I can join with a table on a remote machine using one query? Or run a SELECT INTO into a local table.
Notes
I'm using C# & .NET 4.
This can be done by using the FEDERATED storage engine for the remote table. Find out more.

Cross table join using MYSQL rather than MSSQL

Is it possible to do a cross table join in mysql spaning different tables? in different databases.
This seem to be easily possible in MSSQL, and greatly speeds up data transfer?
How about mysql, do you need to use a powerful IDE to achieve this? or do you have to write a program to do something like this?
UPDATE tblUser
SET tblUser.ReceiveInfo=old_database.dbo.contact.third_party_info_yn
FROM tblUser inner join old_database.dbo.contact
ON old_database.dbo.contact.id=tblUser.oldid
Sure, very easy. Prefix the table name with the database name, like you show. We do cross-database joins on a regular basis. For example:
SELECT COUNT(*) FROM newusers1.users
JOIN newusers2.users
It certainly won't speed up data transfer compared to having both tables in the same database, though.
Now, if your tables are sitting on different database servers, the answer is no. An example of this is if your database is too big and you need to shard your tables. Things get more than a little messy. But given that you seem to be happy with the MS SQL solution, that does not seem to apply here.
In MySQL you can do cross DB joins and, by way of the FEDERATED engine, even cross server joins.
MySQL doesn't actually care if the tables are in the same "database", it's just a logical collection of tables for convenient administration, permissions etc.
So you can do a join between them just as easily as if they were in the same one (see ChrisInEdmonton's answer)