B
Bob Weiner
I have been troubleshooting an SQL query and it turns out that the problem
is my lack of understanding. Hopefully, someone here can explain.
Basically, I have two tables each containing a single field called 'letter'.
I have the following:
Table A: {a, b, c, d, NULL, a}
Table B: {c, d, e, f}
The following two queries generate expected results:
1. SELECT A.letter FROM A WHERE A.letter IN (SELECT B.letter FROM B)
Result: {c, d}
2. SELECT A.letter FROM A WHERE A.letter NOT IN (SELECT B.letter FROM B)
Result: {a, b, a}
Then I add a NULL value to Table B (B = {c, d, e, f, NULL}) and rerun the
same queries.
1. SELECT A.letter FROM A WHERE A.letter IN (SELECT B.letter FROM B)
Result: {c, d}
2. SELECT A.letter FROM A WHERE A.letter NOT IN (SELECT B.letter FROM B)
Result: {} (empty set)
Why does query 2 return different results when Table B contains a NULL?
MySql returns the same results.
Thanks
bob
is my lack of understanding. Hopefully, someone here can explain.
Basically, I have two tables each containing a single field called 'letter'.
I have the following:
Table A: {a, b, c, d, NULL, a}
Table B: {c, d, e, f}
The following two queries generate expected results:
1. SELECT A.letter FROM A WHERE A.letter IN (SELECT B.letter FROM B)
Result: {c, d}
2. SELECT A.letter FROM A WHERE A.letter NOT IN (SELECT B.letter FROM B)
Result: {a, b, a}
Then I add a NULL value to Table B (B = {c, d, e, f, NULL}) and rerun the
same queries.
1. SELECT A.letter FROM A WHERE A.letter IN (SELECT B.letter FROM B)
Result: {c, d}
2. SELECT A.letter FROM A WHERE A.letter NOT IN (SELECT B.letter FROM B)
Result: {} (empty set)
Why does query 2 return different results when Table B contains a NULL?
MySql returns the same results.
Thanks
bob