ASH
ASH

Reputation: 20302

How to Find Non Matches in Both Tables?

I came up with the query below, which finds all non matches in my 'tbl_Master_ME_List'. What I really want to do is find non matches in BOTH tables. Is that possible? Of, do I need two queries to do this and one union to join them together?

SELECT [4 digit Code]
FROM tbl_Master_ME_List B
WHERE NOT EXISTS (
    SELECT *
    FROM tbl_ME_List A
    WHERE A.[4 digit Code] = B.[4 digit Code])

I'm using SQL Server 2014.

Thanks!

Upvotes: 1

Views: 63

Answers (1)

S3S
S3S

Reputation: 25112

select [4 digit code]
from tbl_Master_ME_List a
full outer join tbl_ME_List b on
a.[4 digit code] = b.[4 digit code]
where a.[4 digit code] is null or b.[4 digit code] is null

Upvotes: 3

Related Questions