Re: NOT IN operator not working with subquery.

From: Michel Walsh (vanderghast_at_VirusAreFunnierThanSpam)
Date: 10/27/04


Date: Wed, 27 Oct 2004 06:18:02 -0400

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

  • RE: Query stopped working after entry 615 in table
    ... Macro Name: Find Jenish Invoice ... Table Name: Previous Invoices For Tracking ... How many records does Jenish Invoice Query pull? ...
    (microsoft.public.access.queries)
  • RE: Saving Form
    ... If it is a query, ... You HAVE the computer record of the invoice that you want. ... > everything we need to know about our inventory ex. ... >> would execute a report for the current record. ...
    (microsoft.public.access.forms)
  • RE: Saving Form
    ... ok well the form is bound to a query where the only thing in it is the "in ... You HAVE the computer record of the invoice that you want. ... >> everything we need to know about our inventory ex. ... >>> would execute a report for the current record. ...
    (microsoft.public.access.forms)
  • RE: Saving Form
    ... There would be no need to print an extra hard copy of each invoice ... would execute a report for the current record. ... an Update query is simply a type of query that changes data in ... Show the InvoiceItems and the Inventory tables. ...
    (microsoft.public.access.forms)
  • Re: Can (should) an auto number be set up on a invoice (report)?
    ... The staff takes the customer information (stored in the ... The staff then records what procedures the customer wants ... This table stores Customer ID, Concatenated Customer Name (separate query), ... Procedure, Cost, Sales Tax) except for the invoice number. ...
    (microsoft.public.access.reports)