Identify 3 equal results in 3 different mysql BDs

0

I have an application in php that I created that clever several ips, in some sites I use, I would like to list the same ips in 3 sites in a single list! How do I do it?

Biggest Problem: The tables in the databases have the same name, only the banks that do not. They're all on my server. but different domains.

    
asked by anonymous 13.04.2017 / 19:10

1 answer

0

Some options:

1 Assuming you have a user who has access to the 3 databases (on the same server). Then, it does a query with INNER JOIN looking for IPs that occur in the 3 banks.

SELECT *
FROM db1.tabela_ips AS a
INNER JOIN db2.tabela_ips b ON a.num_ip = b.num_ip
INNER JOIN db3.tabela_ips c ON b.num_ip = c.num_ip

In this case, only the IPs that occur in the 3 banks will be displayed.

2 Starting from the same previous premise, this query generates a single list with all the data and then removes the duplicate items.

SELECT DISTINCT ip 
FROM (
SELECT * FROM db1.tabela_ips
UNION
SELECT * FROM db2.tabela_ips
UNION
SELECT * FROM db3.tabela_ips
) t

3 If each bank has a unique user, then you make a PHP script that connects and fetches the data from the 3 banks and then uses a array_merge function to join the 3 lists and delete the duplicates (as in case 2) .

    
13.04.2017 / 22:45