473,508 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SELECT NOT IN query not working

1 New Member
Hello All,

Thank you for your thoughtful consideration.

I am running Access 2000 (9.0.3821 SR-1)

This query works:

Expand|Select|Wrap|Line Numbers
  1. SELECT [id], [name]
  2. FROM table1
  3. WHERE id NOT IN (SELECT document_type_id FROM table2 WHERE case_type_id=case_type_id ) AND id NOT IN (SELECT document_type_id FROM table3 WHERE case_number='case_number')
  4. ORDER BY name;
Against these tables:

Expand|Select|Wrap|Line Numbers
  1. table1
  2. id                     AutoNumber (Primary Key)
  3. name               Text
  4. description       Text
  5. date_create      Date/Time (General Date)
  6. date_update     Date/Time (General Date)
Expand|Select|Wrap|Line Numbers
  1. table2
  2. id                           AutoNumber (Primary Key)
  3. case_type_id          Number (Long Integer)
  4. document_type_id   Number (Long Integer)
  5. date_create             Date/Time (General Date)
  6. date_update            Date/Time (General Date)
Expand|Select|Wrap|Line Numbers
  1. table3
  2. id                                       AutoNumber (Primary Key)
  3. case_number                      Text
  4. delay_type_id                      Number (Long Integer)
  5. document_type_id               Number (Long Integer)
  6. other_document_type Id       Number (Long Integer)
  7. event_open_date                 Date/Time (Short Date)
  8. event_close_date                 Date/Time (Short Date)
  9. date_create                         Date/Time (General Date)
  10. date_update                        Date/Time (General Date)
But this query returns nothing:

Expand|Select|Wrap|Line Numbers
  1. SELECT [id], [name]
  2. FROM table4
  3. WHERE case_number='case_number' AND id NOT IN (SELECT other_document_type_id FROM table3 WHERE case_number='case_number')
  4. ORDER BY name;
Against this table and same above:

Expand|Select|Wrap|Line Numbers
  1. table4
  2. id                           AutoNumber (Primary Key)
  3. case_number          Text
  4. name                      Memo
  5. date_create             Date/Time (General Date)
  6. date_update            Date/Time (General Date)
The syntax between the two queries is almost identical and there aren't many
differences between the tables.

There are 3 records in table4 for a case_number and only 1 is in table3, so
I would expect a return of two records. I get nothing.

If I remove the NOT IN clause it returns all three records from table4.

If I change it to IN I get the 1 record that is also in table3.

This is very strange.

case_type and case_number are values taken from an active form.

I am unable to find discussion regarding SELECT queries with NOT IN clauses.

Thank you for any help.
Jun 19 '07 #1
1 3079
Rabbit
12,516 Recognized Expert Moderator MVP
When refering to controls on forms, you use:
Forms![FormName]![ControlName]
Jun 19 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

17
2615
by: guitarromantic | last post by:
Hey everyone. I'm re-writing a php Content Management System (based loosely on phpNuke but specific to my site). My first major change was attempting to normalise the Review section database...
5
11487
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
17
4972
by: kalamos | last post by:
This statement fails update ded_temp a set a.balance = (select sum(b.ln_amt) from ded_temp b where a.cust_no = b.cust_no and a.ded_type_cd = b.ded_type_cd and a.chk_no = b.chk_no group by...
3
6425
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
5
11433
by: SuffrinMick | last post by:
Hello - I'm a newbie to coding! I'm working on an access 2000 database which has three tables: tblContacts - A list of customer contacts. tblOrgTypes - A list of organisational types....
9
2841
by: MLH | last post by:
I have a table (tblCorrespondence) holding records with fields like , , , , , , , etc... About a dozen 's are defined and I often use queries to extract records of a given . That's pretty easy....
12
1648
by: bokke | last post by:
Hi, I have a page with a link <a href="Contributor.php?action=&SubCat=<?php echo $row; ?>"><?php echo $row;?></a> that does to a page with a SELECT $query = "SELECT * FROM news WHERE...
1
3606
by: zafm86 | last post by:
Hi everyone! I'm sure my problem is pretty easy to solve but I've been working on it for a long and my my brain is not working correctly anymore. I'm working with an AS400 and I mhave to do an...
1
1628
by: atishrg | last post by:
Hello All, I am facing one strange problem.. I am using a select query in my function which will return specified product details according to product code selected by user.. here is the...
45
27637
by: dizzydangler | last post by:
Hi, I'm new to access (2007, running on XP), but I've gotten some great help from this site on my project so far. However, the more I know, the more complex the problems seem to become.... I'm...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5060
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3201
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.