Results 1 to 5 of 5
  1. #1
    soLost is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Jul 2017
    Posts
    2

    Access query where AccountID has only one criteria

    Doing a query where I am trying to differentiate between accounts with Sites that have a Status of "ND" only, not Sites with both "ND" and "D".



    Table:
    AccountID -- Site -- Status
    ABC -- 1 -- D
    ABC -- 2 -- ND
    123 -- 1 -- ND

    So my query should only show 123 because ABC had both.

    Right now I have a query that pulls all Accounts that has both "D" & "ND" and can do a query that one pulls either but can't work out how to only pull ones that have only "ND" and no "D". Accounts can have over 100 sites.

    If someone can point me in the right direction, thanks


    Here is my code for pulling accounts that have both
    Code:
    SELECT DISTINCT AccountID, "PND" AS AdjStatus FROM 
        table
    WHERE 
        Status = "D" 
    AND AccountID IN (SELECT AccountID FROM table WHERE Status = "ND");

  2. #2
    JoeM is offline VIP
    Windows 7 32bit Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    How about:
    Code:
    SELECT DISTINCT AccountID, "PND" AS AdjStatus FROM 
        table
    WHERE 
        Status = "ND" 
    AND NOT AccountID IN (SELECT AccountID FROM table WHERE Status = "D");

  3. #3
    andy49's Avatar
    andy49 is offline VIP
    Windows 10 Access 2010 64bit
    Join Date
    Nov 2016
    Location
    London
    Posts
    1,051
    Code:
    SELECT DISTINCT AccountID, "PND" AS AdjStatus FROM tbl1
    WHERE Status = "ND" AND AccountID NOT IN (SELECT AccountID FROM tbl1 WHERE Status = "d");

  4. #4
    soLost is offline Novice
    Windows 8 Access 2013 64bit
    Join Date
    Jul 2017
    Posts
    2
    Thanks, this is working!

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    Earlier post https://stackoverflow.com/questions/...24568#45224568

    Basically same question and solution technique, slightly different criteria.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Corect Criteria in a MS Access query
    By Lou_Reed in forum Access
    Replies: 18
    Last Post: 05-25-2016, 12:01 PM
  2. Replies: 3
    Last Post: 09-16-2015, 04:38 PM
  3. Replies: 7
    Last Post: 04-30-2014, 06:55 AM
  4. query criteria in access 2007
    By jeskit in forum Access
    Replies: 2
    Last Post: 11-23-2011, 06:44 AM
  5. Excel not using Access query criteria
    By thart21 in forum Queries
    Replies: 10
    Last Post: 04-30-2010, 09:58 AM

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