2017-08-30 62 views
0

基本上我要完成的,是我想要的test.zfirewallaudit.src_iptest.zfirewallaudit.dst_ip領域加入對inventory.dns_zones.ip列,所以我基本上可以有一個準確的主機名(inventory.dns_zones.subdomain)爲test.zfirewallaudit.src_iptest.zfirewallaudit.dst_ip 。所以基本上我想要一個src_ip子域的列和一個dst_ip子域的列。Mysql的留在同一列加入多個列

SELECT test.zfirewallaudit.src_ip, 
test.zfirewallaudit.src_zone, 
test.zfirewallaudit.dst_ip, 
test.zfirewallaudit.dst_zone, 
test.zfirewallaudit.dst_port, 
test.zfirewallaudit.rulename, 
test.zfirewallaudit.application, 
inventory.dns_zones.subdomain 
FROM test.zfirewallaudit LEFT JOIN inventory.dns_zones ON zfirewallaudit.src_ip = inventory.dns_zones.ip OR zfirewallaudit.dst_ip = inventory.dns_zones.ip LIMIT 10; 

問題是,我需要的inventory.dns_zones.subdomain同時爲test.zfirewallaudit.src_ip...dst_ip值。當前的查詢只給我1 subdomain

回答

1

你需要加入對inventory.dns_zones兩次,一次用於src和曾經爲DST:

SELECT test.zfirewallaudit.src_ip, 
test.zfirewallaudit.src_zone, 
test.zfirewallaudit.dst_ip, 
test.zfirewallaudit.dst_zone, 
test.zfirewallaudit.dst_port, 
test.zfirewallaudit.rulename, 
test.zfirewallaudit.application, 
dns_zones_src.subdomain, 
dns_zones_dst.subdomain 
FROM test.zfirewallaudit 
LEFT JOIN inventory.dns_zones AS dns_zones_src ON (zfirewallaudit.src_ip = dns_zones_src.ip) 
LEFT JOIN inventory.dns_zones AS dns_zones_dst ON (zfirewallaudit.dst_ip = dns_zones_dst.ip) 
LIMIT 10;