Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
266 views
in Technique[技术] by (71.8m points)

sql - Compare columns but exclude specific pairs

I want to write query to compare columns between two tables but to exclude specific pairs which point to the same thing but are written differently.

ID Name
1 NYSE
2 OTC
3 OTC

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have some kind of lookup table, you could use a NOT EXISTS to check the value isn't in the other table:

SELECT ST.[Name]
FROM dbo.SecondTable ST
WHERE NOT EXISTS (SELECT 1
                  FROM dbo.LookupTable LT
                       JOIN dbo.FirstTable FT ON LT.FirstTableID = FT.ID
                  WHERE LT.SecondTableID = ST.ID);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...