How do I do a search between several db and present the result on the page itself?

1

In MySQL I have a database and inside it I have the student table, and I would like to search in another database that is identical to the first, but with different information, and would like to know in which of the banks the student is created.

This search would display the result on the page itself, and I have that doubt and I am not able to unroll it.

Note: this code can be in php or JavaScript .

    
asked by anonymous 17.01.2017 / 20:36

1 answer

2

If the databases are all on the same server, just enter the database name before the table name.

For example, Assuming you have two databases, DB1 and DB2:

Query example querying DB1:

SELECT * FROM DB1.Student WHERE ...

Query example querying DB2:

SELECT * FROM DB2.Student WHERE ...

Query example using both:

SELECT s1.nome, s2.nome FROM DB1.Student as s1
JOIN DB2.Student as s2 ON s2.id = s1.id
    
17.01.2017 / 22:14