473,813 Members | 2,579 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 3095
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
2639
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 structure. I've created a Staff table with staff email addresses and names (plus id), and a Reviews table with the text of the reviews. The Reviews table contains an 'author' field with a value that corresponds to the Staff table. When I display a...
5
11511
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 { CarsSoldID int (primary key) MonthID int DealershipID int NumberCarsSold int
17
5034
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 cust_no, ded_type_cd, chk_no)
3
6476
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 COULD be wrong... :) I've tried the access group...twice...and all I get is "Access doesn't like ".", which I know, or that my query names are too long, as there's a limit to the length of the SQL statement(s). But this works when I don't try to...
5
11450
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. tblPositions - A list of job descriptions (Contacts can hold more than one position) I want to use a multi-select list box (Containing alphabetical list of positions) to run a query. HELP!
9
2861
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. But, recently, I wanted to list all "15" letters, a few of the above mentioned fields and one additional field: of nother letter "00" in the same row. That's the tough part.
12
1681
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 writer='$SubCat' ";
1
3620
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 "interface" in Access. It's like a little system to make a production plan. It must get information about part numbers, description, set where the part number belongs, quantity of part numbers that the set uses, stock number(this is a text value, it...
1
1644
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 query.. Select p_code,p_desc from P_St where p_code = '" + cbotext + "' for all other code selected by user it is working fine ..but when user selected a procuct code as 'c9721comp' its failed ,, when I write a select query using Like
45
27772
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 working with all of my data in a single table and, right now, I've got a form linked to a query that allows the user to input whatever search criteria they want through a variety of controls. I've also created a series of check boxes on the form...
0
9734
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10667
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10422
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10139
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9222
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5705
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
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 we have to send another system
2
3885
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.