[SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Frank Joerdens
When doing a subselect with NOT IN, as in SELECT name FROM customer WHERE customer_id NOT IN ( SELECT customer_id FROM salesorder ); (from Bruce Momjian's book) I get no rows if the result column returned by the subselect contains NULL values. It works as expected if I remove the NULL values

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Josh Berkus
Mr. Joerdens, I get no rows if the result column returned by the subselect contains NULL values. It works as expected if I remove the NULL values from the result set. Is this behaviour correct and if so, why? I can see how that bug would happen. You may want to forward your e-mail to

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Bruce Momjian
When doing a subselect with NOT IN, as in SELECT name FROM customer WHERE customer_id NOT IN ( SELECT customer_id FROM salesorder ); (from Bruce Momjian's book) I get no rows if the result column returned by the subselect contains NULL values. It works as expected if I remove the

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Peter Eisentraut
Frank Joerdens writes: When doing a subselect with NOT IN, as in SELECT name FROM customer WHERE customer_id NOT IN ( SELECT customer_id FROM salesorder ); (from Bruce Momjian's book) I get no rows if the result column returned by the subselect contains NULL values. It works as

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Stephan Szabo
On Thu, 1 Mar 2001, Frank Joerdens wrote: When doing a subselect with NOT IN, as in SELECT name FROM customer WHERE customer_id NOT IN ( SELECT customer_id FROM salesorder ); (from Bruce Momjian's book) I get no rows if the result column returned by the subselect contains NULL

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Ken Kline
this is kind of weird but it is how it works. You cannot use equality for null... Null does not equal Null Null means no value, since it's not a value it can't equal anything another no value. SELECT name FROM customer WHERE customer_id NOT IN ( SELECT customer_id FROM salesorder ) and

Re: [SQL] Weird NOT IN effect with NULL values

2001-03-01 Thread Bruce Momjian
SELECT name FROM customer WHERE NOT EXISTS ( SELECT customer_id FROM salesorder WHERE customer_id = customer.customer_id ); Bruce, you may want to consider editing your next edition to include the above modification. WHERE ... NOT IN is a bad idea for any subselect on medium-large