mysql查询通过比较2个表来获取唯一的缺失值

时间:2016-08-31 09:35:34

标签: mysql

master table1名称:master_port
port_name(列名)
ABC
SDF
EFR
GTY
FGH

NMU
LOI
KUJ
SEC
FFR
ETY

table2&3 details

我需要来自table2和table3(都是orgin_port和destination_port)的端口列表,这些端口列表在主表1中找不到名称:master_port 我怎么得到那些使用mysql查询 请帮我解决这个问题

1 个答案:

答案 0 :(得分:0)

SELECT tab.port FROM
(SELECT origin_port AS port FROM location1
UNION DISTINCT
SELECT destination_port AS port FROM  location1
UNION DISTINCT
SELECT origin_port AS port FROM sender2
UNION DISTINCT
SELECT destination_port AS port FROM  sender2) tab
WHERE tab.port NOT IN 
(SELECT port_name FROM master_port);

这两个表location1和sender2中的返回源和目标端口在master_port

中找不到