Results 1 to 5 of 5
  1. #1
    spsoisson is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2012
    Posts
    2

    A query that excludes certain records based on the existence of other records...

    i have a table that was sent to me imported from Excel (tblAllSpec). The field on which my criteria is based is called "SpecType". The table will be integrated into my database eventually, but i have to pull some numbers out before that happens. The field that will eventually be the Primary Key in the parent table is "SBNumber". SO, there are a bunch of records with duplicate SBNumbers with many different SpecTypes.



    What i need to determine is what SBNumbers have records WHERE SpecType = 'Type1' and NO records WHERE SpecType = 'Type2'. This seems like such a simple thing but I can't seem to get anything to work.

    Thanks! I am relatively new to this and still feeling my way around...

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    In the Query , use the SpecType field in two columns and enter criteria as =Type1 for one and <>Type2 for the other.
    Does this solves you purpose ?

  3. #3
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I think you will need a query with a subquery

    SELECT SBNumber
    FROM tablename
    WHERE spectype="Type 1" and SBNumber NOT IN (SELECT SBNumber From tablename WHERE spectype="Type 2")

  4. #4
    spsoisson is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Aug 2012
    Posts
    2
    i thought it might be an EXISTS/NOT EXISTS issue.

    i tried this:

    SELECT DISTINCT A.SBNumber
    FROM tblAllSpec as A
    WHERE (A.SpecType = 'Type1') AND NOT EXISTS (Select SBNumber from tblAllSpec as B Where B.SBNumber = A.SBNumber
    and B.SpecType = 'Type2');

    this returns results >0 and <total number of records in the table, so it's at least doing something ;-)

    @jzwp11, seems we were thinking similar things. @amrut, i believe that what i did was a roundabout way of accomplishing what you suggested.

    Thanks so much, guys!

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome.

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

Similar Threads

  1. Access 2007 - Creating New Records Based on Existing Records
    By GeorgeAugustinePhillips in forum Forms
    Replies: 9
    Last Post: 10-05-2011, 05:58 PM
  2. Replies: 12
    Last Post: 08-30-2011, 03:36 PM
  3. Replies: 5
    Last Post: 10-15-2010, 01:19 PM
  4. checking existence of records
    By akbigcat86 in forum Programming
    Replies: 6
    Last Post: 07-20-2010, 02:45 PM
  5. How to Add New Records based upon Query?
    By SteveAb in forum Database Design
    Replies: 0
    Last Post: 08-06-2009, 10:24 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