mohan raj mohan raj - 3 months ago 8
MySQL Question

mysql query to get unique missing values with comparing 2 tables

master table1 Name: master_port

port_name (column name)

ABC

SDF

EFR

GTY

FGH

KIU

NMU

LOI

KUJ

SEC

FFR

ETY

table2&3 details

I need port list from table2 and table3(both orgin_port and destination_port) thats not found in the master table1 Name: master_port
how do i get those using mysql query
please help me to resole this

Answer
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);

This return origin and destination port in both tables location1 and sender2 which are not found in master_port

Comments