Você precisa agrupar a coluna
infection e (ip &ipc ) de forma diferente, junte-os usando uma subconsulta como esta:SELECT t1.ip, t1.isp, t2.infection, t1.ipc, t1. ispc, t2.incount
FROM
(SELECT ip, isp, infection, COUNT(ip) as ipc, COUNT(isp) as ispc
FROM (
SELECT ip, isp, infection
FROM tbl1
UNION ALL
SELECT ip, isp, infection
FROM tbl2
UNION ALL
SELECT ip, isp, infection
FROM tbl3
)x
GROUP BY ip, isp) t1
JOIN
(SELECT ip, isp, infection, COUNT(infection) as incount
FROM (
SELECT ip, isp, infection
FROM tbl1
UNION ALL
SELECT ip, isp, infection
FROM tbl2
UNION ALL
SELECT ip, isp, infection
FROM tbl3
)x
GROUP BY ip, isp, infection)t2
ON t1.ip = t2.ip
ORDER BY ip, isp, infection Desc
Veja este SQLFiddle
Observação: Eu acho que sua saída desejada está errada porque:
- Na
Table3não háinfectionparaip=6mas está na sua saída infectionotherestá faltando na sua saída (em vez disso, hámalware)