Identify 3 equal results in 3 different BD mysql

Asked

Viewed 34 times

0

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

Major Problem: Database tables have the same name, only banks that do not. They are all on my server. but different domains.

  • Assemble an array that groups the ips of all databases.

1 answer

0

Some options:

1 Assuming you have a user who has access to all 3 databases (on the same server). Then, make a query with INNER JOIN searching 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 of all data and then removes 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 database has a unique user, then you make a PHP script that connects and fetches the data from the 3 databases and then use a function array_merge to merge the 3 lists and exclude duplicates (as in case 2).

Browser other questions tagged

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