One way to compare table contents
Lets say you have 2 tables
Cars: modelid, manufacturerid, ... some more car related columns
Airplanes: modelid, manufacturerid, ... some more airplane related columns
Task: determine, which car manufacturers don't make airplanes, and vise-versa.
SELECT c.manufacturerName, 'only cars' as specialization
FROM cars c LEFT JOIN
airplanes a ON c.manufacturerid = a.manufacturerid
WHERE a.manufacturerid IS NULL
UNION ALL
SELECT a.manufacturerName, 'only airplanes' as specialization
FROM cars c RIGHT JOIN
airplanes a ON c.manufacturerid = a.manufacturerid
WHERE c.manufacturerid IS NULL
Results here should be like
Mazda, only cars
Toyota, only cars
Airbus, only airplanes
And companies like these should not show because their record will be in both tables
Honda, Mitsubishi, Saab, Ford, Fiat
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…