Results 1 to 5 of 5
  1. #1
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187

    Query to find records that exist and do not exist

    I have a permissions table that stores UserID and PermissionID. This table has records that links a UserID's to PermissionID's where a user can have multiple permissions.



    Column1=UserID, Column2=PermissionID
    1 34
    1 75
    1 98
    2 75
    2 21
    3 75
    4 75

    I am trying to write a query that will find which permission id's are common to all users and which are 'ala cart'. This seems like it should be simple but I cannot figure it out.

    In the above example data, I'd like to retrieve 75 as being a common permission, and 34,98,21 being ala cart.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    select permissions, count(permissions) as countOfPerm from table

    the higher counts would be common

  3. #3
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    That will not quite work.

    If I got the below results I am not getting a definitive answer:
    34 38
    98 25
    21 23
    75 21

    Not looking for counts here, I want the actual permissions to be listed that are common to all, and those not common to all. These can be two separate queries.

  4. #4
    BRZ-Ryan is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Nov 2013
    Posts
    187
    Disregard. I'm going to use VBA/DAO to get a count of agents, then get a count of each permission and if the agent count = permission count then it is common to all. All others are ala cart. Thank you

  5. #5
    knarfreppep is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Feb 2015
    Location
    Adelaide, Australia
    Posts
    106

    Try this -

    SELECT tblPermissions.strDescription AS Permission, Count(tblUserPermissions.bytUser) AS [Number of Users with this Permission], IIf(Not Count([bytUser])=(SELECT Count(bytID) FROM tblUsers),"Yes") AS [A la carte]
    FROM tblUserPermissions LEFT JOIN tblPermissions ON tblUserPermissions.bytPermission = tblPermissions.bytID
    GROUP BY tblPermissions.strDescription
    ORDER BY tblPermissions.strDescription;


    . tblUsers has fields bytID and strName and three rows: 1,U1; 2,U2; and 3,U3
    . tblPermissions has fields bytID and strdescription and three rows: 1,P1; 2,P2; and 3,P3
    . tblUserPermissions has fields bytUser and bytPermission and seven rows: 1,1; 1,2; 1,3; 2,1; 2,2; 3,1; and 3,3

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

Similar Threads

  1. Replies: 4
    Last Post: 03-03-2015, 01:36 PM
  2. Replies: 2
    Last Post: 01-23-2015, 12:14 PM
  3. Replies: 11
    Last Post: 10-28-2014, 01:24 PM
  4. Replies: 8
    Last Post: 09-10-2013, 05:32 PM
  5. If no records exist
    By mrwhitehat in forum Reports
    Replies: 1
    Last Post: 08-27-2013, 12:51 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