How to make an INNER JOIN between two different databases on the same server in MYSQL?

Asked

Viewed 12,357 times

4

I’d like to lay a INNER JOIN between two distinct tables but that are on the same server. It would be something like?

INNER JOIN BANCOA.tabelaA.colunaA ON BANCOA.tabelaA.colunaA = BANCOB.tabelaB.colunaB

Remembering that I’m doing this on MYSQL and tables are on the same server.

  • Take a look here -> https://stackoverflow.com/questions/1144051/selecting-data-from-two-different-servers-in-sql-server

  • @Feliperodrigues if my answer does not help try to detail your problem better.

2 answers

4


All I had to do was remove the first **colunaA** you have in query, simple example:

SELECT * 
FROM banco1.tabela1
INNER JOIN banco2.tabela1 ON banco1.tabela1.campo1=banco2.tabela1.campo1

You just need to do the select previous to work all right.

More information on INNER JOIN.

If you want more information about select tables on different servers see here at PT in EN.

3

Whereas the bank user has the appropriate permissions, yes.

As can be seen in this topic (English), considering a base A and a base B, one can do

SELECT <...> FROM A.tabelaA TA JOIN B.tabelaB TB ON TA.colunaA = TB.colunaB;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.