Results 1 to 4 of 4
  1. #1
    bcirka is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3

    Query using multiple <> criteria across multiple fields

    I have a simple table:
    ID Field1 Field2
    2 Brian Blue
    3 Brian Yellow
    4 John Yellow

    I want to query it where it selects those records that do not equal "Brian" in Field1 AND do not equal "Blue" in Field 2. My SQL code is below (interpreted from MS Access' GUI).

    SELECT Table1.Field1, Table1.Field2 INTO test
    FROM Table1


    WHERE (((Table1.Field1)<>"Brian") AND ((Table1.Field2)<>"Blue"));

    When I run the query, it results in :
    Field1 Field2
    John
    Yellow


    Whereas I expect it to pull BOTH the bottom two records. Can anyone assist?

    (N.b. This is an example of a dataset that I am try to similarly query, but it has a few million rows.)

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Then you want a different logic...OR.. if you can have BRIAN but not YELLOW.

    field1 not brian
    or
    field2 not Yellow
    put this on separate criteria lines
    --------------------------
    not brian
    --------------------------
    not yellow
    ---------------------------

  3. #3
    bcirka is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3
    Thanks for the response. I guess I'm still having a conceptual problem with this. If I only want to exclude the records which contain "Brian" (Field1) AND "Blue" (Field2) , then why would I use OR? It seems to me that OR would be used if I wanted to exclude records where Field1 = "Brian" or Field2 = "Blue".

  4. #4
    bcirka is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2014
    Posts
    3
    To add to my last comment:

    The statement below works (I pulled it out of MS Access' SQL, and cut down on someone of the syntax for better readability in this post). Now, I'm looking for the EXACT OPPOSITE of this statement. I want to exclude all 'Outbound shipments out of Testville'. Just not sure how to make this work, or what to put in which line.

    WHERE ((([Origin City]="Testville" Or ([Origin City] Is Null) AND (([Transportation Type Description])="Outbound" Or [Transportation Type Description] Is Null));

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query multiple fields for the same criteria
    By labratKY in forum Queries
    Replies: 3
    Last Post: 08-07-2014, 02:37 PM
  2. Replies: 1
    Last Post: 02-19-2014, 05:49 PM
  3. Replies: 2
    Last Post: 04-10-2013, 03:54 PM
  4. Replies: 7
    Last Post: 01-02-2013, 11:23 PM
  5. Replies: 5
    Last Post: 08-07-2012, 10:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums