mysql中的多表联合并且去重排序

同一数据库中au_log_开头的表,表中ipsrc和ipdst、portsrc和portdst字段将这些4元组去重后显示出来,并按照某个字段排序
$result = $db->query("
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_baseline where node_name = '".$deviceName."'  group by ipsrc,ipdst,portsrc,portdst )
            UNION 
             (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_ics_pro where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_ics_wl where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_ip_bl where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_mac_bl where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_noflow where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_system where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_tcp where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_udp where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
            UNION 
            (SELECT ipsrc,ipdst,portsrc,portdst FROM au_log_user where node_name = '".$deviceName."' group by ipsrc,ipdst,portsrc,portdst)
             order by ipsrc asc
            ");




你可能感兴趣的:(SQL)