Hello,
given the following tables, how would I go about finding the most common ip address across all tables, and ideally, the number of times that ip occurs across all tables.
bad_guys_1 bad_guys_2
| id | ip | | id | ip |
+----+---------+ +----+---------+
| 1 | 1.2.3.4 | | 1 | 1.2.3.4 |
| 2 | 2.3.4.5 | | 2 | 4.5.6.7 |
| 3 | 3.4.5.6 | | 3 | 1.2.3.4 |
bad_guys_3 bad_guys_4
| id | ip | | id | ip |
+----+---------+ +----+---------+
| 1 | 9.8.7.6 | | 1 | 1.2.3.4 |
| 2 | 8.7.6.5 | | 2 | 2.3.4.5 |
| 3 | 2.3.4.5 | | 3 | 3.4.5.6 |
For example, querying the above tables should result in something like:
| ip | count |
+---------+-------+
| 1.2.3.4 | 4 |
| 2.3.4.5 | 3 |
| 3.4.5.6 | 2 |
| 4.5.6.7 | 1 |
| 9.8.7.6 | 1 |
| 8.7.6.5 | 1 |
The real tables actually contain many additional fields which don't line up with each other, thus separate tables. I don't really care about breaking ties between matches, just listing them in descending order by count would be great. My database is PostGreSQL if using any non-standard functions will assist, but for portability would prefer to use standard sql if possible. Thanks and let me know if you need any more detail.