Re: NOT IN operator not working with subquery.

From: Terry (ttrapp.spam.me.not_at_org.insurors)
Date: 10/27/04


Date: Wed, 27 Oct 2004 10:00:17 -0500

Michel,
    That was it exactly. Thank you so much.

-- Terry

"Michel Walsh" <vanderghast@VirusAreFunnierThanSpam> wrote in message
news:uTozZ5AvEHA.1308@TK2MSFTNGP09.phx.gbl...
> Hi,
>
>
> It does not return any record? Probably there is a NULL in values returned
> by the SELECT. Here is why.
>
>
>
> x IN( a, b, c)
>
> is the same as
>
> x=a OR x=b OR x=c
>
>
>
> x NOT IN(a, b, c)
>
> is thus the same as
>
> x <> a AND x <> b AND x <> c
>
>
>
> If "c" is NULL, x <> NULL returns null, and thus, the last AND
sequence
> returns NULL. Now,
>
> WHERE NULL
>
> does not accept the record. Since that is the case for all records, all
the
> records are rejected.
>
>
> In summary,
>
> WHERE x NOT IN( SELECT ... )
>
>
> will not return ANY record if the SELECT returns a NULL. With JET, if
the
> list is constant, rather than coming from a SELECT, the NULL is NOT
> considered when the evaluation is performed.
>
>
> ? eval( " 4 NOT IN( NULL , 5, 6) " )
> -1
>
>
>
> but the "behavior" stands for a IN list from a SELECT.
>
>
>
>
> Hoping it may help,
> Vanderghast, Access MVP
>
>
> "Terry" <ttrapp.spam.me.not@org.insurors> wrote in message
> news:U0zfd.38$YE4.7@fe61.usenetserver.com...
> >I want to get a list of company names that we have in our database, that
we
> > have not ever sent an invoice to. Why does the following query not work?
I
> > have been banging my head on this for about an hour and can't figure it
> > out.
> > Any help would be much appreciated.
> >
> > SELECT [Companyinfo].[Name], [Companyinfo].[ID#] FROM [Companyinfo]
WHERE
> > [Companyinfo].[ID#] NOT IN (SELECT [Link ID] FROM [Invoices]);
> >
> > [Invoices].[Link ID] points to [Companyinfo].[ID#]
> >
> > -- Terry
> >
> >
> >
>
>



Relevant Pages

  • Using a query as a lookup table
    ... In my Accounts database, the user sometimes needs to store invoices in a ... Invoice dated 29/12/07 may sometimes have to go in the Jan08 folder. ... store the invoice but actually, instead of adding items to this Year/Month ... table when a new year starts, I could generate the year/months using a query ...
    (microsoft.public.access.tablesdbdesign)
  • how to execute a query from form event
    ... I have a form that extracts unbilled clients from my database via a query. ... The form has a button whose event handler sends the client an invoice via ...
    (microsoft.public.access.forms)
  • Re: Question - Update Query
    ... that row in a grid. ... database will continue to inscrease 1. ... Of course the query does not work. ... The immediate thing that springs to mind is to create a Stored Prodcedure that uses a Cursor to walk the Invoice of interest backwards ...
    (microsoft.public.vb.enterprise)
  • Re: make table question
    ... >I have 3 tables that are ODBC connections to our database. ... >tables have invoice number as a field. ... >used the new table in a query to tie all 3 tables together. ...
    (microsoft.public.access.queries)
  • NOT IN operator not working with subquery.
    ... I want to get a list of company names that we have in our database, ... have not ever sent an invoice to. ... have been banging my head on this for about an hour and can't figure it out. ...
    (microsoft.public.access.queries)

Loading