Results 1 to 8 of 8
  1. #1
    russmann2000 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2017
    Posts
    9

    Multiple possibilities for one field causing duplicate records for one person.


    Ok, so I have an issue with a query. I have a table with a field called "license" with possibilities of "driver", "hunting", "fishing", "liquor", and such that could populate that field. One person can have multiple records because they can have all of these particular licenses. For the "hunting" and "fishing" licenses, since they are essentially the same, I want to be able to have only the "hunting" record appear in the query results if both "hunting" and "fishing" licenses appear in the table. I just can't for the life of me figure out how to do this. Your help is greatly appreciated!

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    it the tLicense table has fields:[LicType] and [OwnerID]
    then 1 person can have mutiple licenses.

    query :
    select * from tLicense where [LicType]='Hunting'

  3. #3
    russmann2000 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2017
    Posts
    9
    That’s gonna pull nothing but hunting, I want all of the other types to show as well. Only if “hunting” and “fishing” are in the table for one person, to exclude the fishing record, but all other types should show as well, “liquor”, “driver”, etc.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    A Person can have 0 or Many License(s)
    A License is for Hunting or driving or fishing or liquor or ???

    Person--->License<---- LicenseType

    Using ranmans set up

    select * from tLicense where OwnerID = 1234;

  5. #5
    russmann2000 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2017
    Posts
    9
    That won’t work either. It’s only gonna pull a specific person and it is not excluding the fishing license based on if a person has both a fishing and hunting license.

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Why do you store fishing license if you don't intend to retrieve it?
    If you set your tables up as suggested, you can use a query or queries to get whatever you need.
    The key is to identify exactly what you need; design for it and proceed.

    Select * from tLicense where
    OwnerID = 1234 and
    licenseType <>"Fishing" etc. etc.

    For more see this by Allen Browne.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I gather you want all licenses except when a person has fishing and hunting, exclude the fishing, but if they have fishing and no hunting, include the fishing. This will be tricky. Consider:

    SELECT Table1.UserID, Table1.License
    FROM (SELECT Table1.UserID, Table1.License AS HLic
    FROM Table1
    WHERE (((Table1.License)="Hunting"))) AS Query1
    RIGHT JOIN Table1 ON Query1.UserID = Table1.UserID
    WHERE (((IIf([License]="Fishing" And Not [HLic] Is Null,"HandF","NoH"))="NoH"));
    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.

  8. #8
    russmann2000 is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2017
    Posts
    9
    Orange, that is not the point, the tables are set up the way they are set up. I have zero control over that. I have to work with what i have.

    June7, thank you so much. I will work with that.

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

Similar Threads

  1. Duplicate records Multiple fields
    By UT227 in forum Access
    Replies: 2
    Last Post: 09-23-2017, 08:02 AM
  2. Replies: 11
    Last Post: 03-02-2017, 12:52 PM
  3. delete duplicate records based on multiple criteria
    By sfgiantsdude in forum Access
    Replies: 1
    Last Post: 09-21-2015, 01:22 PM
  4. Replies: 2
    Last Post: 04-04-2012, 03:52 AM
  5. Replies: 10
    Last Post: 04-19-2011, 03:38 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