Re: Difference between = and IN
From: Andy (Andy_at_discussions.microsoft.com)
Date: 02/07/05
- Next message: Phil: "Where Statements"
- Previous message: Hugo Kornelis: "Re: Difference between = and IN"
- In reply to: Hugo Kornelis: "Re: Difference between = and IN"
- Next in thread: Hugo Kornelis: "Re: Difference between = and IN"
- Reply: Hugo Kornelis: "Re: Difference between = and IN"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 7 Feb 2005 07:19:02 -0800
Hi Hugo
I misunderstood what you meant in the previous post. I have worked out in
the past that you have to use 'IS [NOT] NULL' rather than '<> Null' (or 'IN
Null' or '= Null'). I thought you meant that NOT IN (1,2) would return
strange results if Nulls were present in the records whereas (I believe) NOT
IN (1,2) would return all rows that did not contain a 1, 2 or Null.
Its good to know why NOT IN (1,2,NULL) doesn't work though - I should
probably try reading the ANSI standard...
Thanks very much
Andy
"Hugo Kornelis" wrote:
> On Mon, 7 Feb 2005 06:17:04 -0800, Andy wrote:
>
> >Hi Hugo
> >
> >Thanks for this - I wasn't aware there was an issue with IN/NOT IN and
> >Nulls! I was under the impression that Nulls would just be excluded from the
> >results.
>
> Hi Andy,
>
> That's what most people think - but it's not true.
>
> WHERE Column1 NOT IN (1, 2, NULL)
>
> will (as per the ANSI-standard SQL-92) be equivalent to
>
> WHERE Column1 <> 1
> AND Column1 <> 2
> AND Column1 <> NULL
>
> And since Column1 <> NULL is neither "true" nor "false", but "unknown",
> this expression can only evaulate to "false" (as a result of "false" AND
> "unknown") or "unknown" (as a result of "true" and "unknown").
>
> Consider it like this - would you be willing to bet a significant amount
> that the 40 is NOT IN (your age, George W. Bush's age, my age)?
>
> Best, Hugo
> --
>
> (Remove _NO_ and _SPAM_ to get my e-mail address)
>
- Next message: Phil: "Where Statements"
- Previous message: Hugo Kornelis: "Re: Difference between = and IN"
- In reply to: Hugo Kornelis: "Re: Difference between = and IN"
- Next in thread: Hugo Kornelis: "Re: Difference between = and IN"
- Reply: Hugo Kornelis: "Re: Difference between = and IN"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|