Currently I have two tables Table_A and Table_B.
Table_A
ID
1
2
2
3
3
4
Table_B
ID Alphabet
1 X
1 Y
2 X
2 Y
2 Z
3 X
3 Z
4 X
I want to group the column ID and Alphabet from Table_B and find out which group in the combination has the alphabet Z in it.
Then whichever group has Z in it, its ID would not be displayed when I look up IDs for Table_A.
Expected Result
ID
1
4
I'm currently using this SELECT statement:
SELECT A.ID FROM Table_A A LEFT JOIN Table_B B
ON A.ID = B.ID WHERE A.ID NOT IN (SELECT B.ID FROM Table_B
WHERE Alphabet = 'Z' GROUP BY B.ID, Alphabet)
Actual Result
ID
1
1
2
2
3
4
It removes the IDs that has the Alphabet Z in it but it does not relate to other duplicate IDs.