Wednesday, 21 August 2013

UNION ALL and NOT IN together

UNION ALL and NOT IN together

I have 3 simple tables (Fname, Lname and Exceptions) with one column each
called Name. I want my end result to look like: (Everybody in Fname +
Everybody in LName) - (Everybody in Exceptions).
FName:
Name
A
B
LName:
Name
Y
Z
Exceptions:
Name
A
Z
Expected Query Result Set:
B
Y
Current SQL Query:
Select Name from Fname
UNION ALL
Select Name from Lname
WHERE Name NOT IN
(Select Name from Exceptions)
The SQL query only works on removing data which appears in LName but not
in Fname. Can somebody please help.

No comments:

Post a Comment