Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...