Re: Weird NOT IN effect with NULL values

From: Ken Kline <ken(at)oldbs(dot)com>
To: Frank Joerdens <frank(at)joerdens(dot)de>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Weird NOT IN effect with NULL values
Date: 2001-03-01 18:32:52
Message-ID: 3A9E95D4.77C1594@oldbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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 customer_id is not null;

should work

Ken

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 values. It works as expected if I remove the NULL values
> from the result set. Is this behaviour correct and if so, why?
>
> I am using 7.1 beta 4.
>
> Regards, Frank

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2001-03-01 18:42:10 Re: Weird NOT IN effect with NULL values
Previous Message Josh Berkus 2001-03-01 18:32:07 Re: Weird NOT IN effect with NULL values