Re: NOT IN with a subquery
From: Jacco Schalkwijk (jacco.please.reply_at_to.newsgroups.mvps.org.invalid)
Date: 01/20/05
- Next message: Jacco Schalkwijk: "Re: Simply add two columns together"
- Previous message: JJ: "Simply add two columns together"
- In reply to: Louis Davidson: "Re: NOT IN with a subquery"
- Next in thread: Louis Davidson: "Re: NOT IN with a subquery"
- Reply: Louis Davidson: "Re: NOT IN with a subquery"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 20 Jan 2005 23:03:59 -0000
Louis,
Small correction: If there is a NULL in the list for the IN clause, the IN
clause will evaluate to UNKNOWN for all the values that are not otherwise in
the list, not to FALSE.
IF 1 NOT IN (NULL) OR 1 IN (NULL)
SELECT 'FALSE OR TRUE'
ELSE SELECT 'UNKNOWN'
-- Jacco Schalkwijk SQL Server MVP "Louis Davidson" <dr_dontspamme_sql@hotmail.com> wrote in message news:ehXJ0A0$EHA.1908@TK2MSFTNGP15.phx.gbl... > NULLs. If source is NULL then the IN clause will be NULL, which is > evaluated to FALSE. Do you have null values for source? > > Probably need to change to: > > select distinct dp_source > from clients > where dp_source NOT IN(select distinct source from applicat) > or dp_source is null > > -- > ---------------------------------------------------------------------------- > Louis Davidson - drsql@hotmail.com > SQL Server MVP > > Compass Technology Management - www.compass.net > Pro SQL Server 2000 Database Design - > http://www.apress.com/book/bookDisplay.html?bID=266 > Note: Please reply to the newsgroups only unless you are interested in > consulting services. All other replies may be ignored :) > > "news.microsoft.com" <Darwin@DotNetDesigns.com> wrote in message > news:Ozn1l5z$EHA.1524@TK2MSFTNGP09.phx.gbl... >> This query returns 155 rows: >> select distinct dp_source from clients >> >> This query returns 97 rows: >> select distinct dp_source from clients where dp_source IN(select distinct >> source from applicat) >> >> This query returns 0 rows: >> select distinct dp_source from clients where dp_source NOT IN(select >> distinct source from applicat) >> >> If there are 155 rows and 97 are IN my subquery, I would expect 58 rows >> NOT IN my subquery.... >> >> What am I missing? >> >> Thanks, >> Darwin >> > >
- Next message: Jacco Schalkwijk: "Re: Simply add two columns together"
- Previous message: JJ: "Simply add two columns together"
- In reply to: Louis Davidson: "Re: NOT IN with a subquery"
- Next in thread: Louis Davidson: "Re: NOT IN with a subquery"
- Reply: Louis Davidson: "Re: NOT IN with a subquery"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|